@webiny/api-headless-cms 0.0.0-unstable.6e5425ee89 → 0.0.0-unstable.78f581c1d2

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 (272) hide show
  1. package/context.js +15 -0
  2. package/context.js.map +1 -1
  3. package/crud/contentEntry/afterDelete.js +5 -0
  4. package/crud/contentEntry/afterDelete.js.map +1 -1
  5. package/crud/contentEntry/beforeCreate.js +3 -0
  6. package/crud/contentEntry/beforeCreate.js.map +1 -1
  7. package/crud/contentEntry/beforeUpdate.js +3 -0
  8. package/crud/contentEntry/beforeUpdate.js.map +1 -1
  9. package/crud/contentEntry/entryDataValidation.js +40 -1
  10. package/crud/contentEntry/entryDataValidation.js.map +1 -1
  11. package/crud/contentEntry/markLockedFields.js +25 -2
  12. package/crud/contentEntry/markLockedFields.js.map +1 -1
  13. package/crud/contentEntry/referenceFieldsMapping.js +59 -5
  14. package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
  15. package/crud/contentEntry.crud.js +145 -27
  16. package/crud/contentEntry.crud.js.map +1 -1
  17. package/crud/contentModel/afterCreate.js +2 -0
  18. package/crud/contentModel/afterCreate.js.map +1 -1
  19. package/crud/contentModel/afterCreateFrom.js +2 -0
  20. package/crud/contentModel/afterCreateFrom.js.map +1 -1
  21. package/crud/contentModel/afterDelete.js +2 -0
  22. package/crud/contentModel/afterDelete.js.map +1 -1
  23. package/crud/contentModel/afterUpdate.js +2 -0
  24. package/crud/contentModel/afterUpdate.js.map +1 -1
  25. package/crud/contentModel/beforeCreate.js +32 -4
  26. package/crud/contentModel/beforeCreate.js.map +1 -1
  27. package/crud/contentModel/beforeDelete.js +10 -0
  28. package/crud/contentModel/beforeDelete.js.map +1 -1
  29. package/crud/contentModel/beforeUpdate.js +5 -0
  30. package/crud/contentModel/beforeUpdate.js.map +1 -1
  31. package/crud/contentModel/contentModelManagerFactory.js +7 -0
  32. package/crud/contentModel/contentModelManagerFactory.js.map +1 -1
  33. package/crud/contentModel/createFieldModels.js +6 -0
  34. package/crud/contentModel/createFieldModels.js.map +1 -1
  35. package/crud/contentModel/createFieldStorageId.js +2 -0
  36. package/crud/contentModel/createFieldStorageId.js.map +1 -1
  37. package/crud/contentModel/fieldIdValidation.js +5 -0
  38. package/crud/contentModel/fieldIdValidation.js.map +1 -1
  39. package/crud/contentModel/idValidation.js +5 -0
  40. package/crud/contentModel/idValidation.js.map +1 -1
  41. package/crud/contentModel/models.js +8 -1
  42. package/crud/contentModel/models.js.map +1 -1
  43. package/crud/contentModel/systemFields.js.map +1 -1
  44. package/crud/contentModel/validateLayout.js +8 -0
  45. package/crud/contentModel/validateLayout.js.map +1 -1
  46. package/crud/contentModel/validateModel.js +8 -0
  47. package/crud/contentModel/validateModel.js.map +1 -1
  48. package/crud/contentModel/validateModelFields.js +60 -8
  49. package/crud/contentModel/validateModelFields.js.map +1 -1
  50. package/crud/contentModel.crud.js +96 -11
  51. package/crud/contentModel.crud.js.map +1 -1
  52. package/crud/contentModelGroup/beforeCreate.js +12 -0
  53. package/crud/contentModelGroup/beforeCreate.js.map +1 -1
  54. package/crud/contentModelGroup/beforeDelete.js +8 -0
  55. package/crud/contentModelGroup/beforeDelete.js.map +1 -1
  56. package/crud/contentModelGroup/beforeUpdate.js +5 -0
  57. package/crud/contentModelGroup/beforeUpdate.js.map +1 -1
  58. package/crud/contentModelGroup.crud.js +47 -10
  59. package/crud/contentModelGroup.crud.js.map +1 -1
  60. package/crud/index.js +16 -0
  61. package/crud/index.js.map +1 -1
  62. package/crud/settings.crud.js +12 -0
  63. package/crud/settings.crud.js.map +1 -1
  64. package/crud/system.crud.js +37 -2
  65. package/crud/system.crud.js.map +1 -1
  66. package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +13 -0
  67. package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js.map +1 -1
  68. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +53 -0
  69. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
  70. package/fieldConverters/index.js +4 -0
  71. package/fieldConverters/index.js.map +1 -1
  72. package/graphql/buildSchemaPlugins.js +9 -5
  73. package/graphql/buildSchemaPlugins.js.map +1 -1
  74. package/graphql/graphQLHandlerFactory.js +28 -3
  75. package/graphql/graphQLHandlerFactory.js.map +1 -1
  76. package/graphql/index.js +8 -1
  77. package/graphql/index.js.map +1 -1
  78. package/graphql/schema/baseContentSchema.js +9 -1
  79. package/graphql/schema/baseContentSchema.js.map +1 -1
  80. package/graphql/schema/contentEntries.js +42 -2
  81. package/graphql/schema/contentEntries.js.map +1 -1
  82. package/graphql/schema/contentModelGroups.js +19 -2
  83. package/graphql/schema/contentModelGroups.js.map +1 -1
  84. package/graphql/schema/contentModels.js +18 -2
  85. package/graphql/schema/contentModels.js.map +1 -1
  86. package/graphql/schema/createFieldResolvers.js +21 -3
  87. package/graphql/schema/createFieldResolvers.js.map +1 -1
  88. package/graphql/schema/createManageResolvers.js +26 -0
  89. package/graphql/schema/createManageResolvers.js.map +1 -1
  90. package/graphql/schema/createManageSDL.js +14 -1
  91. package/graphql/schema/createManageSDL.js.map +1 -1
  92. package/graphql/schema/createPreviewResolvers.js +10 -0
  93. package/graphql/schema/createPreviewResolvers.js.map +1 -1
  94. package/graphql/schema/createReadResolvers.js +10 -0
  95. package/graphql/schema/createReadResolvers.js.map +1 -1
  96. package/graphql/schema/createReadSDL.js +10 -0
  97. package/graphql/schema/createReadSDL.js.map +1 -1
  98. package/graphql/schema/resolvers/commonFieldResolvers.js +2 -0
  99. package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -1
  100. package/graphql/schema/resolvers/manage/resolveCreate.js +3 -0
  101. package/graphql/schema/resolvers/manage/resolveCreate.js.map +1 -1
  102. package/graphql/schema/resolvers/manage/resolveCreateFrom.js +3 -0
  103. package/graphql/schema/resolvers/manage/resolveCreateFrom.js.map +1 -1
  104. package/graphql/schema/resolvers/manage/resolveDelete.js +6 -0
  105. package/graphql/schema/resolvers/manage/resolveDelete.js.map +1 -1
  106. package/graphql/schema/resolvers/manage/resolveGet.js +16 -0
  107. package/graphql/schema/resolvers/manage/resolveGet.js.map +1 -1
  108. package/graphql/schema/resolvers/manage/resolveGetByIds.js +3 -0
  109. package/graphql/schema/resolvers/manage/resolveGetByIds.js.map +1 -1
  110. package/graphql/schema/resolvers/manage/resolveGetRevisions.js +3 -0
  111. package/graphql/schema/resolvers/manage/resolveGetRevisions.js.map +1 -1
  112. package/graphql/schema/resolvers/manage/resolveList.js +3 -0
  113. package/graphql/schema/resolvers/manage/resolveList.js.map +1 -1
  114. package/graphql/schema/resolvers/manage/resolvePublish.js +3 -0
  115. package/graphql/schema/resolvers/manage/resolvePublish.js.map +1 -1
  116. package/graphql/schema/resolvers/manage/resolveRepublish.js +3 -0
  117. package/graphql/schema/resolvers/manage/resolveRepublish.js.map +1 -1
  118. package/graphql/schema/resolvers/manage/resolveUnpublish.js +3 -0
  119. package/graphql/schema/resolvers/manage/resolveUnpublish.js.map +1 -1
  120. package/graphql/schema/resolvers/manage/resolveUpdate.js +3 -0
  121. package/graphql/schema/resolvers/manage/resolveUpdate.js.map +1 -1
  122. package/graphql/schema/resolvers/preview/resolveGet.js +8 -0
  123. package/graphql/schema/resolvers/preview/resolveGet.js.map +1 -1
  124. package/graphql/schema/resolvers/preview/resolveList.js +3 -0
  125. package/graphql/schema/resolvers/preview/resolveList.js.map +1 -1
  126. package/graphql/schema/resolvers/read/resolveGet.js +8 -0
  127. package/graphql/schema/resolvers/read/resolveGet.js.map +1 -1
  128. package/graphql/schema/resolvers/read/resolveList.js +3 -0
  129. package/graphql/schema/resolvers/read/resolveList.js.map +1 -1
  130. package/graphql/schema/schemaPlugins.js +19 -5
  131. package/graphql/schema/schemaPlugins.js.map +1 -1
  132. package/graphql/system.js +14 -1
  133. package/graphql/system.js.map +1 -1
  134. package/graphqlFields/boolean.js +12 -0
  135. package/graphqlFields/boolean.js.map +1 -1
  136. package/graphqlFields/datetime.js +17 -0
  137. package/graphqlFields/datetime.js.map +1 -1
  138. package/graphqlFields/file.js +8 -0
  139. package/graphqlFields/file.js.map +1 -1
  140. package/graphqlFields/helpers.js +10 -0
  141. package/graphqlFields/helpers.js.map +1 -1
  142. package/graphqlFields/index.js +11 -0
  143. package/graphqlFields/index.js.map +1 -1
  144. package/graphqlFields/longText.js +10 -0
  145. package/graphqlFields/longText.js.map +1 -1
  146. package/graphqlFields/number.js +12 -0
  147. package/graphqlFields/number.js.map +1 -1
  148. package/graphqlFields/object.js +36 -6
  149. package/graphqlFields/object.js.map +1 -1
  150. package/graphqlFields/ref.js +51 -17
  151. package/graphqlFields/ref.js.map +1 -1
  152. package/graphqlFields/richText.js +9 -0
  153. package/graphqlFields/richText.js.map +1 -1
  154. package/graphqlFields/text.js +11 -0
  155. package/graphqlFields/text.js.map +1 -1
  156. package/index.js +19 -0
  157. package/index.js.map +1 -1
  158. package/modelManager/DefaultCmsModelManager.js +16 -0
  159. package/modelManager/DefaultCmsModelManager.js.map +1 -1
  160. package/modelManager/index.js +4 -0
  161. package/modelManager/index.js.map +1 -1
  162. package/package.json +24 -24
  163. package/parameters/context.js +4 -0
  164. package/parameters/context.js.map +1 -1
  165. package/parameters/header.js +11 -0
  166. package/parameters/header.js.map +1 -1
  167. package/parameters/index.js +8 -0
  168. package/parameters/index.js.map +1 -1
  169. package/parameters/manual.js +8 -1
  170. package/parameters/manual.js.map +1 -1
  171. package/parameters/path.js +11 -0
  172. package/parameters/path.js.map +1 -1
  173. package/plugins/CmsGroupPlugin.js +8 -0
  174. package/plugins/CmsGroupPlugin.js.map +1 -1
  175. package/plugins/CmsModelFieldConverterPlugin.js +5 -0
  176. package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
  177. package/plugins/CmsModelPlugin.js +38 -2
  178. package/plugins/CmsModelPlugin.js.map +1 -1
  179. package/plugins/CmsParametersPlugin.js +7 -0
  180. package/plugins/CmsParametersPlugin.js.map +1 -1
  181. package/plugins/StorageTransformPlugin.js +9 -0
  182. package/plugins/StorageTransformPlugin.js.map +1 -1
  183. package/plugins/index.js +10 -0
  184. package/plugins/index.js.map +1 -1
  185. package/storage/default.js +3 -0
  186. package/storage/default.js.map +1 -1
  187. package/storage/object.js +18 -0
  188. package/storage/object.js.map +1 -1
  189. package/types.js +62 -0
  190. package/types.js.map +1 -1
  191. package/upgrades/5.33.0/index.js +26 -3
  192. package/upgrades/5.33.0/index.js.map +1 -1
  193. package/upgrades/index.js +3 -0
  194. package/upgrades/index.js.map +1 -1
  195. package/utils/access.js +25 -11
  196. package/utils/access.js.map +1 -1
  197. package/utils/converters/Converter.js +13 -0
  198. package/utils/converters/Converter.js.map +1 -1
  199. package/utils/converters/ConverterCollection.js +32 -9
  200. package/utils/converters/ConverterCollection.js.map +1 -1
  201. package/utils/converters/valueKeyStorageConverter.js +26 -0
  202. package/utils/converters/valueKeyStorageConverter.js.map +1 -1
  203. package/utils/createTypeName.js +8 -0
  204. package/utils/createTypeName.js.map +1 -1
  205. package/utils/entryStorage.js +26 -10
  206. package/utils/entryStorage.js.map +1 -1
  207. package/utils/filterAsync.js +5 -0
  208. package/utils/filterAsync.js.map +1 -1
  209. package/utils/filterModelFields.js +9 -3
  210. package/utils/filterModelFields.js.map +1 -1
  211. package/utils/getEntryTitle.js +9 -0
  212. package/utils/getEntryTitle.js.map +1 -1
  213. package/utils/getSchemaFromFieldPlugins.js +6 -2
  214. package/utils/getSchemaFromFieldPlugins.js.map +1 -1
  215. package/utils/ownership.js +8 -0
  216. package/utils/ownership.js.map +1 -1
  217. package/utils/permissions.js +23 -8
  218. package/utils/permissions.js.map +1 -1
  219. package/utils/pluralizedTypeName.js +6 -0
  220. package/utils/pluralizedTypeName.js.map +1 -1
  221. package/utils/renderFields.js +8 -0
  222. package/utils/renderFields.js.map +1 -1
  223. package/utils/renderGetFilterFields.js +11 -0
  224. package/utils/renderGetFilterFields.js.map +1 -1
  225. package/utils/renderInputFields.js +8 -0
  226. package/utils/renderInputFields.js.map +1 -1
  227. package/utils/renderListFilterFields.js +9 -1
  228. package/utils/renderListFilterFields.js.map +1 -1
  229. package/utils/renderSortEnum.js +7 -0
  230. package/utils/renderSortEnum.js.map +1 -1
  231. package/utils/toSlug.js +4 -0
  232. package/utils/toSlug.js.map +1 -1
  233. package/validators/dateGte.js +7 -0
  234. package/validators/dateGte.js.map +1 -1
  235. package/validators/dateLte.js +7 -0
  236. package/validators/dateLte.js.map +1 -1
  237. package/validators/gte.js +8 -0
  238. package/validators/gte.js.map +1 -1
  239. package/validators/in.js +8 -0
  240. package/validators/in.js.map +1 -1
  241. package/validators/index.js +15 -0
  242. package/validators/index.js.map +1 -1
  243. package/validators/lte.js +8 -0
  244. package/validators/lte.js.map +1 -1
  245. package/validators/maxLength.js +8 -0
  246. package/validators/maxLength.js.map +1 -1
  247. package/validators/minLength.js +8 -0
  248. package/validators/minLength.js.map +1 -1
  249. package/validators/pattern.js +9 -0
  250. package/validators/pattern.js.map +1 -1
  251. package/validators/patternPlugins/email.js +2 -0
  252. package/validators/patternPlugins/email.js.map +1 -1
  253. package/validators/patternPlugins/index.js +8 -0
  254. package/validators/patternPlugins/index.js.map +1 -1
  255. package/validators/patternPlugins/lowerCase.js +2 -0
  256. package/validators/patternPlugins/lowerCase.js.map +1 -1
  257. package/validators/patternPlugins/lowerCaseSpace.js +2 -0
  258. package/validators/patternPlugins/lowerCaseSpace.js.map +1 -1
  259. package/validators/patternPlugins/upperCase.js +2 -0
  260. package/validators/patternPlugins/upperCase.js.map +1 -1
  261. package/validators/patternPlugins/upperCaseSpace.js +2 -0
  262. package/validators/patternPlugins/upperCaseSpace.js.map +1 -1
  263. package/validators/patternPlugins/url.js +2 -0
  264. package/validators/patternPlugins/url.js.map +1 -1
  265. package/validators/required.js +5 -0
  266. package/validators/required.js.map +1 -1
  267. package/validators/timeGte.js +8 -0
  268. package/validators/timeGte.js.map +1 -1
  269. package/validators/timeLte.js +8 -0
  270. package/validators/timeLte.js.map +1 -1
  271. package/validators/unique.js +7 -0
  272. package/validators/unique.js.map +1 -1
@@ -4,25 +4,33 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.validateLayout = void 0;
7
+
7
8
  const validateLayout = (layout, fields = []) => {
8
9
  const flatLayoutIdList = layout.reduce((acc, id) => {
9
10
  return acc.concat(Array.isArray(id) ? id : [id]);
10
11
  }, []);
12
+
11
13
  if (flatLayoutIdList.length !== fields.length) {
12
14
  throw new Error(`There are ${flatLayoutIdList.length} IDs in the layout and ${fields.length} in fields, which cannot be - numbers must be the same.`);
13
15
  }
16
+
14
17
  for (const field of fields) {
15
18
  if (flatLayoutIdList.includes(field.id)) {
16
19
  continue;
17
20
  }
21
+
18
22
  throw new Error(`Field "${field.id}" is not defined in layout.`);
19
23
  }
24
+
20
25
  for (const id of flatLayoutIdList) {
21
26
  const fieldFound = fields.some(f => f.id === id);
27
+
22
28
  if (fieldFound) {
23
29
  continue;
24
30
  }
31
+
25
32
  throw new Error(`Field id "${id}" is in layout but not in fields.`);
26
33
  }
27
34
  };
35
+
28
36
  exports.validateLayout = validateLayout;
@@ -1 +1 @@
1
- {"version":3,"names":["validateLayout","layout","fields","flatLayoutIdList","reduce","acc","id","concat","Array","isArray","length","Error","field","includes","fieldFound","some","f"],"sources":["validateLayout.ts"],"sourcesContent":["import { CmsModelField, CmsModel } from \"~/types\";\n\nexport const validateLayout = (layout: CmsModel[\"layout\"], fields: CmsModelField[] = []): void => {\n const flatLayoutIdList = layout.reduce((acc, id) => {\n return acc.concat(Array.isArray(id) ? id : [id]);\n }, []);\n if (flatLayoutIdList.length !== fields.length) {\n throw new Error(\n `There are ${flatLayoutIdList.length} IDs in the layout and ${fields.length} in fields, which cannot be - numbers must be the same.`\n );\n }\n for (const field of fields) {\n if (flatLayoutIdList.includes(field.id)) {\n continue;\n }\n throw new Error(`Field \"${field.id}\" is not defined in layout.`);\n }\n for (const id of flatLayoutIdList) {\n const fieldFound = fields.some(f => f.id === id);\n if (fieldFound) {\n continue;\n }\n throw new Error(`Field id \"${id}\" is in layout but not in fields.`);\n }\n};\n"],"mappings":";;;;;;AAEO,MAAMA,cAAc,GAAG,CAACC,MAA0B,EAAEC,MAAuB,GAAG,EAAE,KAAW;EAC9F,MAAMC,gBAAgB,GAAGF,MAAM,CAACG,MAAM,CAAC,CAACC,GAAG,EAAEC,EAAE,KAAK;IAChD,OAAOD,GAAG,CAACE,MAAM,CAACC,KAAK,CAACC,OAAO,CAACH,EAAE,CAAC,GAAGA,EAAE,GAAG,CAACA,EAAE,CAAC,CAAC;EACpD,CAAC,EAAE,EAAE,CAAC;EACN,IAAIH,gBAAgB,CAACO,MAAM,KAAKR,MAAM,CAACQ,MAAM,EAAE;IAC3C,MAAM,IAAIC,KAAK,CACV,aAAYR,gBAAgB,CAACO,MAAO,0BAAyBR,MAAM,CAACQ,MAAO,yDAAwD,CACvI;EACL;EACA,KAAK,MAAME,KAAK,IAAIV,MAAM,EAAE;IACxB,IAAIC,gBAAgB,CAACU,QAAQ,CAACD,KAAK,CAACN,EAAE,CAAC,EAAE;MACrC;IACJ;IACA,MAAM,IAAIK,KAAK,CAAE,UAASC,KAAK,CAACN,EAAG,6BAA4B,CAAC;EACpE;EACA,KAAK,MAAMA,EAAE,IAAIH,gBAAgB,EAAE;IAC/B,MAAMW,UAAU,GAAGZ,MAAM,CAACa,IAAI,CAACC,CAAC,IAAIA,CAAC,CAACV,EAAE,KAAKA,EAAE,CAAC;IAChD,IAAIQ,UAAU,EAAE;MACZ;IACJ;IACA,MAAM,IAAIH,KAAK,CAAE,aAAYL,EAAG,mCAAkC,CAAC;EACvE;AACJ,CAAC;AAAC"}
1
+ {"version":3,"names":["validateLayout","layout","fields","flatLayoutIdList","reduce","acc","id","concat","Array","isArray","length","Error","field","includes","fieldFound","some","f"],"sources":["validateLayout.ts"],"sourcesContent":["import { CmsModelField, CmsModel } from \"~/types\";\n\nexport const validateLayout = (layout: CmsModel[\"layout\"], fields: CmsModelField[] = []): void => {\n const flatLayoutIdList = layout.reduce((acc, id) => {\n return acc.concat(Array.isArray(id) ? id : [id]);\n }, []);\n if (flatLayoutIdList.length !== fields.length) {\n throw new Error(\n `There are ${flatLayoutIdList.length} IDs in the layout and ${fields.length} in fields, which cannot be - numbers must be the same.`\n );\n }\n for (const field of fields) {\n if (flatLayoutIdList.includes(field.id)) {\n continue;\n }\n throw new Error(`Field \"${field.id}\" is not defined in layout.`);\n }\n for (const id of flatLayoutIdList) {\n const fieldFound = fields.some(f => f.id === id);\n if (fieldFound) {\n continue;\n }\n throw new Error(`Field id \"${id}\" is in layout but not in fields.`);\n }\n};\n"],"mappings":";;;;;;;AAEO,MAAMA,cAAc,GAAG,CAACC,MAAD,EAA6BC,MAAuB,GAAG,EAAvD,KAAoE;EAC9F,MAAMC,gBAAgB,GAAGF,MAAM,CAACG,MAAP,CAAc,CAACC,GAAD,EAAMC,EAAN,KAAa;IAChD,OAAOD,GAAG,CAACE,MAAJ,CAAWC,KAAK,CAACC,OAAN,CAAcH,EAAd,IAAoBA,EAApB,GAAyB,CAACA,EAAD,CAApC,CAAP;EACH,CAFwB,EAEtB,EAFsB,CAAzB;;EAGA,IAAIH,gBAAgB,CAACO,MAAjB,KAA4BR,MAAM,CAACQ,MAAvC,EAA+C;IAC3C,MAAM,IAAIC,KAAJ,CACD,aAAYR,gBAAgB,CAACO,MAAO,0BAAyBR,MAAM,CAACQ,MAAO,yDAD1E,CAAN;EAGH;;EACD,KAAK,MAAME,KAAX,IAAoBV,MAApB,EAA4B;IACxB,IAAIC,gBAAgB,CAACU,QAAjB,CAA0BD,KAAK,CAACN,EAAhC,CAAJ,EAAyC;MACrC;IACH;;IACD,MAAM,IAAIK,KAAJ,CAAW,UAASC,KAAK,CAACN,EAAG,6BAA7B,CAAN;EACH;;EACD,KAAK,MAAMA,EAAX,IAAiBH,gBAAjB,EAAmC;IAC/B,MAAMW,UAAU,GAAGZ,MAAM,CAACa,IAAP,CAAYC,CAAC,IAAIA,CAAC,CAACV,EAAF,KAASA,EAA1B,CAAnB;;IACA,IAAIQ,UAAJ,EAAgB;MACZ;IACH;;IACD,MAAM,IAAIH,KAAJ,CAAW,aAAYL,EAAG,mCAA1B,CAAN;EACH;AACJ,CAtBM"}
@@ -1,24 +1,32 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
8
  exports.validateModel = void 0;
9
+
8
10
  var _error = _interopRequireDefault(require("@webiny/error"));
11
+
9
12
  var _CmsModelPlugin = require("../../plugins/CmsModelPlugin");
13
+
10
14
  var _validateModelFields = require("./validateModelFields");
15
+
11
16
  const validateModel = params => {
12
17
  const {
13
18
  model,
14
19
  plugins
15
20
  } = params;
16
21
  const modelPlugin = plugins.byType(_CmsModelPlugin.CmsModelPlugin.type).find(item => item.contentModel.modelId === model.modelId);
22
+
17
23
  if (modelPlugin) {
18
24
  throw new _error.default("Content models defined via plugins cannot be updated.", "CONTENT_MODEL_UPDATE_ERROR", {
19
25
  modelId: model.modelId
20
26
  });
21
27
  }
28
+
22
29
  (0, _validateModelFields.validateModelFields)(params);
23
30
  };
31
+
24
32
  exports.validateModel = validateModel;
@@ -1 +1 @@
1
- {"version":3,"names":["validateModel","params","model","plugins","modelPlugin","byType","CmsModelPlugin","type","find","item","contentModel","modelId","WebinyError","validateModelFields"],"sources":["validateModel.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsModelPlugin } from \"~/plugins/CmsModelPlugin\";\nimport { CmsModel } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { validateModelFields } from \"~/crud/contentModel/validateModelFields\";\n\ninterface ValidateModelParams {\n model: CmsModel;\n original?: CmsModel;\n plugins: PluginsContainer;\n}\n\nexport const validateModel = (params: ValidateModelParams) => {\n const { model, plugins } = params;\n\n const modelPlugin = plugins\n .byType<CmsModelPlugin>(CmsModelPlugin.type)\n .find(item => item.contentModel.modelId === model.modelId);\n\n if (modelPlugin) {\n throw new WebinyError(\n \"Content models defined via plugins cannot be updated.\",\n \"CONTENT_MODEL_UPDATE_ERROR\",\n {\n modelId: model.modelId\n }\n );\n }\n\n validateModelFields(params);\n};\n"],"mappings":";;;;;;;AAAA;AACA;AAGA;AAQO,MAAMA,aAAa,GAAIC,MAA2B,IAAK;EAC1D,MAAM;IAAEC,KAAK;IAAEC;EAAQ,CAAC,GAAGF,MAAM;EAEjC,MAAMG,WAAW,GAAGD,OAAO,CACtBE,MAAM,CAAiBC,8BAAc,CAACC,IAAI,CAAC,CAC3CC,IAAI,CAACC,IAAI,IAAIA,IAAI,CAACC,YAAY,CAACC,OAAO,KAAKT,KAAK,CAACS,OAAO,CAAC;EAE9D,IAAIP,WAAW,EAAE;IACb,MAAM,IAAIQ,cAAW,CACjB,uDAAuD,EACvD,4BAA4B,EAC5B;MACID,OAAO,EAAET,KAAK,CAACS;IACnB,CAAC,CACJ;EACL;EAEA,IAAAE,wCAAmB,EAACZ,MAAM,CAAC;AAC/B,CAAC;AAAC"}
1
+ {"version":3,"names":["validateModel","params","model","plugins","modelPlugin","byType","CmsModelPlugin","type","find","item","contentModel","modelId","WebinyError","validateModelFields"],"sources":["validateModel.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsModelPlugin } from \"~/plugins/CmsModelPlugin\";\nimport { CmsModel } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { validateModelFields } from \"~/crud/contentModel/validateModelFields\";\n\ninterface ValidateModelParams {\n model: CmsModel;\n original?: CmsModel;\n plugins: PluginsContainer;\n}\n\nexport const validateModel = (params: ValidateModelParams) => {\n const { model, plugins } = params;\n\n const modelPlugin = plugins\n .byType<CmsModelPlugin>(CmsModelPlugin.type)\n .find(item => item.contentModel.modelId === model.modelId);\n\n if (modelPlugin) {\n throw new WebinyError(\n \"Content models defined via plugins cannot be updated.\",\n \"CONTENT_MODEL_UPDATE_ERROR\",\n {\n modelId: model.modelId\n }\n );\n }\n\n validateModelFields(params);\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AAGA;;AAQO,MAAMA,aAAa,GAAIC,MAAD,IAAiC;EAC1D,MAAM;IAAEC,KAAF;IAASC;EAAT,IAAqBF,MAA3B;EAEA,MAAMG,WAAW,GAAGD,OAAO,CACtBE,MADe,CACQC,8BAAA,CAAeC,IADvB,EAEfC,IAFe,CAEVC,IAAI,IAAIA,IAAI,CAACC,YAAL,CAAkBC,OAAlB,KAA8BT,KAAK,CAACS,OAFlC,CAApB;;EAIA,IAAIP,WAAJ,EAAiB;IACb,MAAM,IAAIQ,cAAJ,CACF,uDADE,EAEF,4BAFE,EAGF;MACID,OAAO,EAAET,KAAK,CAACS;IADnB,CAHE,CAAN;EAOH;;EAED,IAAAE,wCAAA,EAAoBZ,MAApB;AACH,CAlBM"}
@@ -1,17 +1,25 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
8
  exports.validateModelFields = void 0;
9
+
8
10
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
+
9
12
  var _error = _interopRequireDefault(require("@webiny/error"));
13
+
10
14
  var _createManageSDL = require("../../graphql/schema/createManageSDL");
15
+
11
16
  var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
17
+
12
18
  var _createFieldStorageId = require("./createFieldStorageId");
19
+
13
20
  const defaultTitleFieldId = "id";
14
21
  const allowedTitleFieldTypes = ["text", "number"];
22
+
15
23
  const getContentModelTitleFieldId = (fields, titleFieldId) => {
16
24
  /**
17
25
  * If there are no fields defined, we will return the default field
@@ -24,6 +32,8 @@ const getContentModelTitleFieldId = (fields, titleFieldId) => {
24
32
  * we will take first text field that has no multiple values enabled
25
33
  * or if initial titleFieldId is the default one also try to find first available text field
26
34
  */
35
+
36
+
27
37
  if (!titleFieldId || titleFieldId === defaultTitleFieldId) {
28
38
  const titleField = fields.find(field => {
29
39
  return field.type === "text" && !field.multipleValues;
@@ -35,13 +45,17 @@ const getContentModelTitleFieldId = (fields, titleFieldId) => {
35
45
  * for correct type
36
46
  * and that it is not multiple values field
37
47
  */
48
+
49
+
38
50
  const target = fields.find(f => f.fieldId === titleFieldId);
51
+
39
52
  if (!target) {
40
53
  throw new _error.default(`Field selected for the title field does not exist in the model.`, "VALIDATION_ERROR", {
41
54
  fieldId: titleFieldId,
42
55
  fields
43
56
  });
44
57
  }
58
+
45
59
  if (allowedTitleFieldTypes.includes(target.type) === false) {
46
60
  throw new _error.default(`Only ${allowedTitleFieldTypes.join(", ")} and id fields can be used as an entry title.`, "ENTRY_TITLE_FIELD_TYPE", {
47
61
  storageId: target.storageId,
@@ -49,6 +63,7 @@ const getContentModelTitleFieldId = (fields, titleFieldId) => {
49
63
  type: target.type
50
64
  });
51
65
  }
66
+
52
67
  if (target.multipleValues) {
53
68
  throw new _error.default(`Fields that accept multiple values cannot be used as the entry title.`, "ENTRY_TITLE_FIELD_TYPE", {
54
69
  storageId: target.storageId,
@@ -56,15 +71,18 @@ const getContentModelTitleFieldId = (fields, titleFieldId) => {
56
71
  type: target.type
57
72
  });
58
73
  }
74
+
59
75
  return target.fieldId;
60
76
  };
77
+
61
78
  const extractInvalidField = (model, err) => {
62
79
  var _err$source;
63
- const sdl = ((_err$source = err.source) === null || _err$source === void 0 ? void 0 : _err$source.body) || "";
64
80
 
81
+ const sdl = ((_err$source = err.source) === null || _err$source === void 0 ? void 0 : _err$source.body) || "";
65
82
  /**
66
83
  * Find the invalid type
67
84
  */
85
+
68
86
  const {
69
87
  line: lineNumber
70
88
  } = err.locations ? err.locations[0] : {
@@ -73,25 +91,33 @@ const extractInvalidField = (model, err) => {
73
91
  const sdlLines = sdl.split("\n");
74
92
  let sdlLine;
75
93
  let gqlType;
94
+
76
95
  for (let i = lineNumber; i > 0; i--) {
77
96
  if (sdlLine && sdlLine.includes("type ")) {
78
97
  gqlType = sdlLine.match(/type\s+(.*?)\s+{/);
79
98
  break;
80
99
  }
100
+
81
101
  sdlLine = sdlLines[i];
82
102
  }
103
+
83
104
  let invalidField = undefined;
105
+
84
106
  if (Array.isArray(gqlType)) {
85
107
  const fieldRegex = new RegExp(`([^\\s+].*?):\\s+\\[?${gqlType[1]}!?\\]?`);
86
108
  const matched = sdl.match(fieldRegex);
109
+
87
110
  if (matched) {
88
111
  invalidField = matched[1];
89
112
  }
90
113
  }
114
+
91
115
  let message = `See more details in the browser console.`;
116
+
92
117
  if (invalidField) {
93
118
  message = `Please review the definition of "${invalidField}" field.`;
94
119
  }
120
+
95
121
  return {
96
122
  data: {
97
123
  modelId: model.modelId,
@@ -102,6 +128,7 @@ const extractInvalidField = (model, err) => {
102
128
  message: [`Model "${model.modelId}" was not saved!`, message].join("\n")
103
129
  };
104
130
  };
131
+
105
132
  const validateFields = params => {
106
133
  const {
107
134
  plugins,
@@ -111,16 +138,21 @@ const validateFields = params => {
111
138
  } = params;
112
139
  const fieldIdList = [];
113
140
  const storageIdList = [];
141
+
114
142
  for (const field of fields) {
115
143
  var _field$settings, _originalField$settin;
144
+
116
145
  const plugin = plugins.find(item => item.fieldType === field.type);
146
+
117
147
  if (!plugin) {
118
148
  throw new Error(`Cannot update content model because of the unknown "${field.type}" field.`);
119
149
  }
150
+
120
151
  const originalField = originalFields.find(f => f.id === field.id);
121
152
  /**
122
153
  * Field MUST have an fieldId defined.
123
154
  */
155
+
124
156
  if (!field.fieldId) {
125
157
  throw new _error.default(`Field does not have an "fieldId" defined.`, "MISSING_FIELD_ID", {
126
158
  field
@@ -139,9 +171,12 @@ const validateFields = params => {
139
171
  * https://discuss.elastic.co/t/special-characters-in-field-names/10658/3
140
172
  * https://discuss.elastic.co/t/illegal-characters-in-elasticsearch-field-names/17196/2
141
173
  */
174
+
175
+
142
176
  const isLocked = lockedFields.some(lockedField => {
143
177
  return lockedField.fieldId === field.storageId;
144
178
  });
179
+
145
180
  if (!field.storageId) {
146
181
  /**
147
182
  * In case field is locked, we must set the storageId to the fieldId value.
@@ -170,35 +205,44 @@ const validateFields = params => {
170
205
  * Check the field's fieldId against existing ones.
171
206
  * There cannot be two fields with the same fieldId - outside world identifier.
172
207
  */
208
+
209
+
173
210
  if (fieldIdList.includes(field.fieldId)) {
174
211
  throw new _error.default(`Cannot update content model because field "${field.storageId}" has fieldId "${field.fieldId}", which is already used.`);
175
212
  }
213
+
176
214
  fieldIdList.push(field.fieldId);
177
215
  /**
178
216
  * Check the field's storageId against the existing ones.
179
217
  * There cannot be two fields with the same storageId.
180
218
  */
219
+
181
220
  if (storageIdList.includes(field.storageId)) {
182
221
  throw new _error.default(`Cannot update content model because field "${field.label}" has storageId "${field.storageId}", which is already used.`);
183
222
  }
223
+
184
224
  storageIdList.push(field.storageId);
185
225
  /**
186
226
  * TODO maybe make this part pluginable?
187
227
  * We need to check the object field child fields.
188
228
  * It must be recursive.
189
229
  */
230
+
190
231
  if (field.type !== "object") {
191
232
  continue;
192
233
  }
234
+
193
235
  const childFields = ((_field$settings = field.settings) === null || _field$settings === void 0 ? void 0 : _field$settings.fields) || [];
194
236
  const originalChildFields = (originalField === null || originalField === void 0 ? void 0 : (_originalField$settin = originalField.settings) === null || _originalField$settin === void 0 ? void 0 : _originalField$settin.fields) || [];
195
237
  /**
196
238
  * No point in going further if there are no child fields.
197
239
  * Code will break if child fields were removed but used in the entries.
198
240
  */
241
+
199
242
  if (childFields.length === 0) {
200
243
  continue;
201
244
  }
245
+
202
246
  validateFields({
203
247
  fields: childFields,
204
248
  originalFields: originalChildFields,
@@ -207,6 +251,7 @@ const validateFields = params => {
207
251
  });
208
252
  }
209
253
  };
254
+
210
255
  const validateModelFields = params => {
211
256
  const {
212
257
  model,
@@ -216,19 +261,19 @@ const validateModelFields = params => {
216
261
  const {
217
262
  titleFieldId
218
263
  } = model;
219
-
220
264
  /**
221
265
  * There should be fields/locked fields in either model or data to be updated.
222
266
  */
267
+
223
268
  const {
224
269
  fields = [],
225
270
  lockedFields = []
226
271
  } = model;
227
-
228
272
  /**
229
273
  * Let's inspect the fields of the received content model. We prevent saving of a content model if it
230
274
  * contains a field for which a "cms-model-field-to-graphql" plugin does not exist on the backend.
231
275
  */
276
+
232
277
  const fieldTypePlugins = plugins.byType("cms-model-field-to-graphql");
233
278
  validateFields({
234
279
  fields,
@@ -236,6 +281,7 @@ const validateModelFields = params => {
236
281
  lockedFields,
237
282
  plugins: fieldTypePlugins
238
283
  });
284
+
239
285
  if (fields.length) {
240
286
  /**
241
287
  * Make sure that this model can be safely converted to a GraphQL SDL
@@ -246,29 +292,30 @@ const validateModelFields = params => {
246
292
  [pl.fieldType]: pl
247
293
  }), {})
248
294
  });
295
+
249
296
  try {
250
297
  (0, _graphqlTag.default)(schema);
251
298
  } catch (err) {
252
299
  throw new _error.default(extractInvalidField(model, err));
253
300
  }
254
301
  }
302
+
255
303
  model.titleFieldId = getContentModelTitleFieldId(fields, titleFieldId);
256
304
  const cmsLockedFieldPlugins = plugins.byType("cms-model-locked-field");
257
-
258
305
  /**
259
306
  * We must not allow removal or changes in fields that are already in use in content entries.
260
307
  * Locked fields still have fieldId (should be storageId) because of the old existing locked fields in the models.
261
308
  */
309
+
262
310
  for (const lockedField of lockedFields) {
263
311
  const existingField = fields.find(item => item.storageId === lockedField.fieldId);
264
-
265
312
  /**
266
313
  * Starting with 5.33.0 fields can be deleted.
267
314
  * Our UI gives a warning upon locked field deletion, but if user is managing fields through API directly - we cannot do anything.
268
315
  */
316
+
269
317
  if (!existingField) {
270
- continue;
271
- // throw new WebinyError(
318
+ continue; // throw new WebinyError(
272
319
  // `Cannot remove the field "${lockedField.fieldId}" because it's already in use in created content.`,
273
320
  // "ENTRY_FIELD_USED",
274
321
  // {
@@ -283,20 +330,24 @@ const validateModelFields = params => {
283
330
  field: existingField
284
331
  });
285
332
  }
333
+
286
334
  if (lockedField.type !== existingField.type) {
287
335
  throw new _error.default(`Cannot change field type for the "${lockedField.fieldId}" field because it's already in use in created content.`, "ENTRY_FIELD_USED", {
288
336
  field: existingField
289
337
  });
290
338
  }
291
-
292
339
  /**
293
340
  * Check `lockedField` invariant for specific field
294
341
  */
342
+
343
+
295
344
  const lockedFieldsByType = cmsLockedFieldPlugins.filter(pl => pl.fieldType === lockedField.type);
345
+
296
346
  for (const plugin of lockedFieldsByType) {
297
347
  if (typeof plugin.checkLockedField !== "function") {
298
348
  continue;
299
349
  }
350
+
300
351
  plugin.checkLockedField({
301
352
  lockedField,
302
353
  field: existingField
@@ -304,4 +355,5 @@ const validateModelFields = params => {
304
355
  }
305
356
  }
306
357
  };
358
+
307
359
  exports.validateModelFields = validateModelFields;
@@ -1 +1 @@
1
- {"version":3,"names":["defaultTitleFieldId","allowedTitleFieldTypes","getContentModelTitleFieldId","fields","titleFieldId","length","titleField","find","field","type","multipleValues","fieldId","target","f","WebinyError","includes","join","storageId","extractInvalidField","model","err","sdl","source","body","line","lineNumber","locations","sdlLines","split","sdlLine","gqlType","i","match","invalidField","undefined","Array","isArray","fieldRegex","RegExp","matched","message","data","modelId","code","validateFields","params","plugins","originalFields","lockedFields","fieldIdList","storageIdList","plugin","item","fieldType","Error","originalField","id","isLocked","some","lockedField","createFieldStorageId","push","label","childFields","settings","originalChildFields","validateModelFields","original","fieldTypePlugins","byType","schema","createManageSDL","reduce","acc","pl","gql","cmsLockedFieldPlugins","existingField","lockedFieldsByType","filter","checkLockedField"],"sources":["validateModelFields.ts"],"sourcesContent":["import {\n CmsModel,\n CmsModelField,\n CmsModelFieldToGraphQLPlugin,\n CmsModelLockedFieldPlugin,\n LockedField\n} from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { createManageSDL } from \"~/graphql/schema/createManageSDL\";\nimport gql from \"graphql-tag\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createFieldStorageId } from \"./createFieldStorageId\";\nimport { GraphQLError } from \"graphql\";\n\nconst defaultTitleFieldId = \"id\";\n\nconst allowedTitleFieldTypes = [\"text\", \"number\"];\n\nconst getContentModelTitleFieldId = (fields: CmsModelField[], titleFieldId?: string): string => {\n /**\n * If there are no fields defined, we will return the default field\n */\n if (fields.length === 0) {\n return defaultTitleFieldId;\n }\n /**\n * if there is no title field defined either in input data or existing content model data\n * we will take first text field that has no multiple values enabled\n * or if initial titleFieldId is the default one also try to find first available text field\n */\n if (!titleFieldId || titleFieldId === defaultTitleFieldId) {\n const titleField = fields.find(field => {\n return field.type === \"text\" && !field.multipleValues;\n });\n return titleField?.fieldId || defaultTitleFieldId;\n }\n /**\n * check existing titleFieldId for existence in the model\n * for correct type\n * and that it is not multiple values field\n */\n const target = fields.find(f => f.fieldId === titleFieldId);\n if (!target) {\n throw new WebinyError(\n `Field selected for the title field does not exist in the model.`,\n \"VALIDATION_ERROR\",\n {\n fieldId: titleFieldId,\n fields\n }\n );\n }\n\n if (allowedTitleFieldTypes.includes(target.type) === false) {\n throw new WebinyError(\n `Only ${allowedTitleFieldTypes.join(\n \", \"\n )} and id fields can be used as an entry title.`,\n \"ENTRY_TITLE_FIELD_TYPE\",\n {\n storageId: target.storageId,\n fieldId: target.fieldId,\n type: target.type\n }\n );\n }\n\n if (target.multipleValues) {\n throw new WebinyError(\n `Fields that accept multiple values cannot be used as the entry title.`,\n \"ENTRY_TITLE_FIELD_TYPE\",\n {\n storageId: target.storageId,\n fieldId: target.fieldId,\n type: target.type\n }\n );\n }\n\n return target.fieldId;\n};\n\nconst extractInvalidField = (model: CmsModel, err: GraphQLError) => {\n const sdl = err.source?.body || \"\";\n\n /**\n * Find the invalid type\n */\n const { line: lineNumber } = err.locations\n ? err.locations[0]\n : {\n line: 0\n };\n const sdlLines = sdl.split(\"\\n\");\n let sdlLine;\n let gqlType;\n for (let i = lineNumber; i > 0; i--) {\n if (sdlLine && sdlLine.includes(\"type \")) {\n gqlType = sdlLine.match(/type\\s+(.*?)\\s+{/);\n break;\n }\n\n sdlLine = sdlLines[i];\n }\n\n let invalidField: string | undefined = undefined;\n if (Array.isArray(gqlType)) {\n const fieldRegex = new RegExp(`([^\\\\s+].*?):\\\\s+\\\\[?${gqlType[1]}!?\\\\]?`);\n\n const matched = sdl.match(fieldRegex);\n if (matched) {\n invalidField = matched[1];\n }\n }\n\n let message = `See more details in the browser console.`;\n if (invalidField) {\n message = `Please review the definition of \"${invalidField}\" field.`;\n }\n\n return {\n data: {\n modelId: model.modelId,\n sdl,\n invalidField\n },\n code: \"INVALID_MODEL_DEFINITION\",\n message: [`Model \"${model.modelId}\" was not saved!`, message].join(\"\\n\")\n };\n};\n\ninterface ValidateFieldsParams {\n plugins: CmsModelFieldToGraphQLPlugin[];\n fields: CmsModelField[];\n originalFields: CmsModelField[];\n lockedFields: LockedField[];\n}\nconst validateFields = (params: ValidateFieldsParams) => {\n const { plugins, fields, originalFields, lockedFields } = params;\n\n const fieldIdList: string[] = [];\n\n const storageIdList: string[] = [];\n\n for (const field of fields) {\n const plugin = plugins.find(item => item.fieldType === field.type);\n if (!plugin) {\n throw new Error(\n `Cannot update content model because of the unknown \"${field.type}\" field.`\n );\n }\n const originalField = originalFields.find(f => f.id === field.id);\n /**\n * Field MUST have an fieldId defined.\n */\n if (!field.fieldId) {\n throw new WebinyError(`Field does not have an \"fieldId\" defined.`, \"MISSING_FIELD_ID\", {\n field\n });\n }\n /**\n * If storageId does not match a certain pattern, add that pattern, but only if field is not locked (used) already.\n * This is to avoid errors in the already installed systems.\n *\n * Why are we using the @?\n *\n * It is not part of special characters for the query syntax in the Lucene.\n *\n * Relevant links:\n * https://lucene.apache.org/core/3_4_0/queryparsersyntax.html\n * https://discuss.elastic.co/t/special-characters-in-field-names/10658/3\n * https://discuss.elastic.co/t/illegal-characters-in-elasticsearch-field-names/17196/2\n */\n const isLocked = lockedFields.some(lockedField => {\n return lockedField.fieldId === field.storageId;\n });\n if (!field.storageId) {\n /**\n * In case field is locked, we must set the storageId to the fieldId value.\n * This should not happen, because we upgrade all the fields in 5.33.0, but let's have a check just in case of some upgrade miss.\n */\n //\n if (isLocked) {\n field.storageId = field.fieldId;\n }\n /**\n * When having original field, just set the storageId to value from the originalField\n */\n //\n else if (originalField) {\n field.storageId = originalField.storageId;\n }\n /**\n * The last case is when no original field and not locked - so this is a completely new field.\n */\n //\n else {\n field.storageId = createFieldStorageId(field);\n }\n }\n /**\n * Check the field's fieldId against existing ones.\n * There cannot be two fields with the same fieldId - outside world identifier.\n */\n if (fieldIdList.includes(field.fieldId)) {\n throw new WebinyError(\n `Cannot update content model because field \"${field.storageId}\" has fieldId \"${field.fieldId}\", which is already used.`\n );\n }\n fieldIdList.push(field.fieldId);\n /**\n * Check the field's storageId against the existing ones.\n * There cannot be two fields with the same storageId.\n */\n if (storageIdList.includes(field.storageId)) {\n throw new WebinyError(\n `Cannot update content model because field \"${field.label}\" has storageId \"${field.storageId}\", which is already used.`\n );\n }\n storageIdList.push(field.storageId);\n /**\n * TODO maybe make this part pluginable?\n * We need to check the object field child fields.\n * It must be recursive.\n */\n if (field.type !== \"object\") {\n continue;\n }\n const childFields = field.settings?.fields || [];\n const originalChildFields = originalField?.settings?.fields || [];\n /**\n * No point in going further if there are no child fields.\n * Code will break if child fields were removed but used in the entries.\n */\n if (childFields.length === 0) {\n continue;\n }\n validateFields({\n fields: childFields,\n originalFields: originalChildFields,\n plugins,\n lockedFields: []\n });\n }\n};\n\ninterface ValidateModelFieldsParams {\n model: CmsModel;\n original?: CmsModel;\n plugins: PluginsContainer;\n}\nexport const validateModelFields = (params: ValidateModelFieldsParams) => {\n const { model, original, plugins } = params;\n const { titleFieldId } = model;\n\n /**\n * There should be fields/locked fields in either model or data to be updated.\n */\n const { fields = [], lockedFields = [] } = model;\n\n /**\n * Let's inspect the fields of the received content model. We prevent saving of a content model if it\n * contains a field for which a \"cms-model-field-to-graphql\" plugin does not exist on the backend.\n */\n const fieldTypePlugins = plugins.byType<CmsModelFieldToGraphQLPlugin>(\n \"cms-model-field-to-graphql\"\n );\n\n validateFields({\n fields,\n originalFields: original?.fields || [],\n lockedFields,\n plugins: fieldTypePlugins\n });\n\n if (fields.length) {\n /**\n * Make sure that this model can be safely converted to a GraphQL SDL\n */\n const schema = createManageSDL({\n model,\n fieldTypePlugins: fieldTypePlugins.reduce(\n (acc, pl) => ({ ...acc, [pl.fieldType]: pl }),\n {}\n )\n });\n\n try {\n gql(schema);\n } catch (err) {\n throw new WebinyError(extractInvalidField(model, err));\n }\n }\n\n model.titleFieldId = getContentModelTitleFieldId(fields, titleFieldId);\n\n const cmsLockedFieldPlugins =\n plugins.byType<CmsModelLockedFieldPlugin>(\"cms-model-locked-field\");\n\n /**\n * We must not allow removal or changes in fields that are already in use in content entries.\n * Locked fields still have fieldId (should be storageId) because of the old existing locked fields in the models.\n */\n for (const lockedField of lockedFields) {\n const existingField = fields.find(item => item.storageId === lockedField.fieldId);\n\n /**\n * Starting with 5.33.0 fields can be deleted.\n * Our UI gives a warning upon locked field deletion, but if user is managing fields through API directly - we cannot do anything.\n */\n if (!existingField) {\n continue;\n // throw new WebinyError(\n // `Cannot remove the field \"${lockedField.fieldId}\" because it's already in use in created content.`,\n // \"ENTRY_FIELD_USED\",\n // {\n // lockedField,\n // fields\n // }\n // );\n }\n\n if (lockedField.multipleValues !== existingField.multipleValues) {\n throw new WebinyError(\n `Cannot change \"multipleValues\" for the \"${lockedField.fieldId}\" field because it's already in use in created content.`,\n \"ENTRY_FIELD_USED\",\n {\n field: existingField\n }\n );\n }\n\n if (lockedField.type !== existingField.type) {\n throw new WebinyError(\n `Cannot change field type for the \"${lockedField.fieldId}\" field because it's already in use in created content.`,\n \"ENTRY_FIELD_USED\",\n {\n field: existingField\n }\n );\n }\n\n /**\n * Check `lockedField` invariant for specific field\n */\n const lockedFieldsByType = cmsLockedFieldPlugins.filter(\n pl => pl.fieldType === lockedField.type\n );\n for (const plugin of lockedFieldsByType) {\n if (typeof plugin.checkLockedField !== \"function\") {\n continue;\n }\n plugin.checkLockedField({\n lockedField,\n field: existingField\n });\n }\n }\n};\n"],"mappings":";;;;;;;;AAOA;AACA;AACA;AAEA;A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C;IACN;EACJ;AACJ,CAAC;AAAC"}
1
+ {"version":3,"names":["defaultTitleFieldId","allowedTitleFieldTypes","getContentModelTitleFieldId","fields","titleFieldId","length","titleField","find","field","type","multipleValues","fieldId","target","f","WebinyError","includes","join","storageId","extractInvalidField","model","err","sdl","source","body","line","lineNumber","locations","sdlLines","split","sdlLine","gqlType","i","match","invalidField","undefined","Array","isArray","fieldRegex","RegExp","matched","message","data","modelId","code","validateFields","params","plugins","originalFields","lockedFields","fieldIdList","storageIdList","plugin","item","fieldType","Error","originalField","id","isLocked","some","lockedField","createFieldStorageId","push","label","childFields","settings","originalChildFields","validateModelFields","original","fieldTypePlugins","byType","schema","createManageSDL","reduce","acc","pl","gql","cmsLockedFieldPlugins","existingField","lockedFieldsByType","filter","checkLockedField"],"sources":["validateModelFields.ts"],"sourcesContent":["import {\n CmsModel,\n CmsModelField,\n CmsModelFieldToGraphQLPlugin,\n CmsModelLockedFieldPlugin,\n LockedField\n} from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { createManageSDL } from \"~/graphql/schema/createManageSDL\";\nimport gql from \"graphql-tag\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createFieldStorageId } from \"./createFieldStorageId\";\nimport { GraphQLError } from \"graphql\";\n\nconst defaultTitleFieldId = \"id\";\n\nconst allowedTitleFieldTypes = [\"text\", \"number\"];\n\nconst getContentModelTitleFieldId = (fields: CmsModelField[], titleFieldId?: string): string => {\n /**\n * If there are no fields defined, we will return the default field\n */\n if (fields.length === 0) {\n return defaultTitleFieldId;\n }\n /**\n * if there is no title field defined either in input data or existing content model data\n * we will take first text field that has no multiple values enabled\n * or if initial titleFieldId is the default one also try to find first available text field\n */\n if (!titleFieldId || titleFieldId === defaultTitleFieldId) {\n const titleField = fields.find(field => {\n return field.type === \"text\" && !field.multipleValues;\n });\n return titleField?.fieldId || defaultTitleFieldId;\n }\n /**\n * check existing titleFieldId for existence in the model\n * for correct type\n * and that it is not multiple values field\n */\n const target = fields.find(f => f.fieldId === titleFieldId);\n if (!target) {\n throw new WebinyError(\n `Field selected for the title field does not exist in the model.`,\n \"VALIDATION_ERROR\",\n {\n fieldId: titleFieldId,\n fields\n }\n );\n }\n\n if (allowedTitleFieldTypes.includes(target.type) === false) {\n throw new WebinyError(\n `Only ${allowedTitleFieldTypes.join(\n \", \"\n )} and id fields can be used as an entry title.`,\n \"ENTRY_TITLE_FIELD_TYPE\",\n {\n storageId: target.storageId,\n fieldId: target.fieldId,\n type: target.type\n }\n );\n }\n\n if (target.multipleValues) {\n throw new WebinyError(\n `Fields that accept multiple values cannot be used as the entry title.`,\n \"ENTRY_TITLE_FIELD_TYPE\",\n {\n storageId: target.storageId,\n fieldId: target.fieldId,\n type: target.type\n }\n );\n }\n\n return target.fieldId;\n};\n\nconst extractInvalidField = (model: CmsModel, err: GraphQLError) => {\n const sdl = err.source?.body || \"\";\n\n /**\n * Find the invalid type\n */\n const { line: lineNumber } = err.locations\n ? err.locations[0]\n : {\n line: 0\n };\n const sdlLines = sdl.split(\"\\n\");\n let sdlLine;\n let gqlType;\n for (let i = lineNumber; i > 0; i--) {\n if (sdlLine && sdlLine.includes(\"type \")) {\n gqlType = sdlLine.match(/type\\s+(.*?)\\s+{/);\n break;\n }\n\n sdlLine = sdlLines[i];\n }\n\n let invalidField: string | undefined = undefined;\n if (Array.isArray(gqlType)) {\n const fieldRegex = new RegExp(`([^\\\\s+].*?):\\\\s+\\\\[?${gqlType[1]}!?\\\\]?`);\n\n const matched = sdl.match(fieldRegex);\n if (matched) {\n invalidField = matched[1];\n }\n }\n\n let message = `See more details in the browser console.`;\n if (invalidField) {\n message = `Please review the definition of \"${invalidField}\" field.`;\n }\n\n return {\n data: {\n modelId: model.modelId,\n sdl,\n invalidField\n },\n code: \"INVALID_MODEL_DEFINITION\",\n message: [`Model \"${model.modelId}\" was not saved!`, message].join(\"\\n\")\n };\n};\n\ninterface ValidateFieldsParams {\n plugins: CmsModelFieldToGraphQLPlugin[];\n fields: CmsModelField[];\n originalFields: CmsModelField[];\n lockedFields: LockedField[];\n}\nconst validateFields = (params: ValidateFieldsParams) => {\n const { plugins, fields, originalFields, lockedFields } = params;\n\n const fieldIdList: string[] = [];\n\n const storageIdList: string[] = [];\n\n for (const field of fields) {\n const plugin = plugins.find(item => item.fieldType === field.type);\n if (!plugin) {\n throw new Error(\n `Cannot update content model because of the unknown \"${field.type}\" field.`\n );\n }\n const originalField = originalFields.find(f => f.id === field.id);\n /**\n * Field MUST have an fieldId defined.\n */\n if (!field.fieldId) {\n throw new WebinyError(`Field does not have an \"fieldId\" defined.`, \"MISSING_FIELD_ID\", {\n field\n });\n }\n /**\n * If storageId does not match a certain pattern, add that pattern, but only if field is not locked (used) already.\n * This is to avoid errors in the already installed systems.\n *\n * Why are we using the @?\n *\n * It is not part of special characters for the query syntax in the Lucene.\n *\n * Relevant links:\n * https://lucene.apache.org/core/3_4_0/queryparsersyntax.html\n * https://discuss.elastic.co/t/special-characters-in-field-names/10658/3\n * https://discuss.elastic.co/t/illegal-characters-in-elasticsearch-field-names/17196/2\n */\n const isLocked = lockedFields.some(lockedField => {\n return lockedField.fieldId === field.storageId;\n });\n if (!field.storageId) {\n /**\n * In case field is locked, we must set the storageId to the fieldId value.\n * This should not happen, because we upgrade all the fields in 5.33.0, but let's have a check just in case of some upgrade miss.\n */\n //\n if (isLocked) {\n field.storageId = field.fieldId;\n }\n /**\n * When having original field, just set the storageId to value from the originalField\n */\n //\n else if (originalField) {\n field.storageId = originalField.storageId;\n }\n /**\n * The last case is when no original field and not locked - so this is a completely new field.\n */\n //\n else {\n field.storageId = createFieldStorageId(field);\n }\n }\n /**\n * Check the field's fieldId against existing ones.\n * There cannot be two fields with the same fieldId - outside world identifier.\n */\n if (fieldIdList.includes(field.fieldId)) {\n throw new WebinyError(\n `Cannot update content model because field \"${field.storageId}\" has fieldId \"${field.fieldId}\", which is already used.`\n );\n }\n fieldIdList.push(field.fieldId);\n /**\n * Check the field's storageId against the existing ones.\n * There cannot be two fields with the same storageId.\n */\n if (storageIdList.includes(field.storageId)) {\n throw new WebinyError(\n `Cannot update content model because field \"${field.label}\" has storageId \"${field.storageId}\", which is already used.`\n );\n }\n storageIdList.push(field.storageId);\n /**\n * TODO maybe make this part pluginable?\n * We need to check the object field child fields.\n * It must be recursive.\n */\n if (field.type !== \"object\") {\n continue;\n }\n const childFields = field.settings?.fields || [];\n const originalChildFields = originalField?.settings?.fields || [];\n /**\n * No point in going further if there are no child fields.\n * Code will break if child fields were removed but used in the entries.\n */\n if (childFields.length === 0) {\n continue;\n }\n validateFields({\n fields: childFields,\n originalFields: originalChildFields,\n plugins,\n lockedFields: []\n });\n }\n};\n\ninterface ValidateModelFieldsParams {\n model: CmsModel;\n original?: CmsModel;\n plugins: PluginsContainer;\n}\nexport const validateModelFields = (params: ValidateModelFieldsParams) => {\n const { model, original, plugins } = params;\n const { titleFieldId } = model;\n\n /**\n * There should be fields/locked fields in either model or data to be updated.\n */\n const { fields = [], lockedFields = [] } = model;\n\n /**\n * Let's inspect the fields of the received content model. We prevent saving of a content model if it\n * contains a field for which a \"cms-model-field-to-graphql\" plugin does not exist on the backend.\n */\n const fieldTypePlugins = plugins.byType<CmsModelFieldToGraphQLPlugin>(\n \"cms-model-field-to-graphql\"\n );\n\n validateFields({\n fields,\n originalFields: original?.fields || [],\n lockedFields,\n plugins: fieldTypePlugins\n });\n\n if (fields.length) {\n /**\n * Make sure that this model can be safely converted to a GraphQL SDL\n */\n const schema = createManageSDL({\n model,\n fieldTypePlugins: fieldTypePlugins.reduce(\n (acc, pl) => ({ ...acc, [pl.fieldType]: pl }),\n {}\n )\n });\n\n try {\n gql(schema);\n } catch (err) {\n throw new WebinyError(extractInvalidField(model, err));\n }\n }\n\n model.titleFieldId = getContentModelTitleFieldId(fields, titleFieldId);\n\n const cmsLockedFieldPlugins =\n plugins.byType<CmsModelLockedFieldPlugin>(\"cms-model-locked-field\");\n\n /**\n * We must not allow removal or changes in fields that are already in use in content entries.\n * Locked fields still have fieldId (should be storageId) because of the old existing locked fields in the models.\n */\n for (const lockedField of lockedFields) {\n const existingField = fields.find(item => item.storageId === lockedField.fieldId);\n\n /**\n * Starting with 5.33.0 fields can be deleted.\n * Our UI gives a warning upon locked field deletion, but if user is managing fields through API directly - we cannot do anything.\n */\n if (!existingField) {\n continue;\n // throw new WebinyError(\n // `Cannot remove the field \"${lockedField.fieldId}\" because it's already in use in created content.`,\n // \"ENTRY_FIELD_USED\",\n // {\n // lockedField,\n // fields\n // }\n // );\n }\n\n if (lockedField.multipleValues !== existingField.multipleValues) {\n throw new WebinyError(\n `Cannot change \"multipleValues\" for the \"${lockedField.fieldId}\" field because it's already in use in created content.`,\n \"ENTRY_FIELD_USED\",\n {\n field: existingField\n }\n );\n }\n\n if (lockedField.type !== existingField.type) {\n throw new WebinyError(\n `Cannot change field type for the \"${lockedField.fieldId}\" field because it's already in use in created content.`,\n \"ENTRY_FIELD_USED\",\n {\n field: existingField\n }\n );\n }\n\n /**\n * Check `lockedField` invariant for specific field\n */\n const lockedFieldsByType = cmsLockedFieldPlugins.filter(\n pl => pl.fieldType === lockedField.type\n );\n for (const plugin of lockedFieldsByType) {\n if (typeof plugin.checkLockedField !== \"function\") {\n continue;\n }\n plugin.checkLockedField({\n lockedField,\n field: existingField\n });\n }\n }\n};\n"],"mappings":";;;;;;;;;;;AAOA;;AACA;;AACA;;AAEA;;AAGA,MAAMA,mBAAmB,GAAG,IAA5B;AAEA,MAAMC,sBAAsB,GAAG,CAAC,MAAD,EAAS,QAAT,CAA/B;;AAEA,MAAMC,2BAA2B,GAAG,CAACC,MAAD,EAA0BC,YAA1B,KAA4D;EAC5F;AACJ;AACA;EACI,IAAID,MAAM,CAACE,MAAP,KAAkB,CAAtB,EAAyB;IACrB,OAAOL,mBAAP;EACH;EACD;AACJ;AACA;AACA;AACA;;;EACI,IAAI,CAACI,YAAD,IAAiBA,YAAY,KAAKJ,mBAAtC,EAA2D;IACvD,MAAMM,UAAU,GAAGH,MAAM,CAACI,IAAP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