@webiny/api-headless-cms 0.0.0-unstable.1e66d121db → 0.0.0-unstable.611c5af35e

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 (274) hide show
  1. package/context.js +0 -15
  2. package/context.js.map +1 -1
  3. package/crud/contentEntry/afterDelete.js +0 -5
  4. package/crud/contentEntry/afterDelete.js.map +1 -1
  5. package/crud/contentEntry/beforeCreate.js +0 -3
  6. package/crud/contentEntry/beforeCreate.js.map +1 -1
  7. package/crud/contentEntry/beforeUpdate.js +0 -3
  8. package/crud/contentEntry/beforeUpdate.js.map +1 -1
  9. package/crud/contentEntry/entryDataValidation.js +1 -40
  10. package/crud/contentEntry/entryDataValidation.js.map +1 -1
  11. package/crud/contentEntry/markLockedFields.js +2 -25
  12. package/crud/contentEntry/markLockedFields.js.map +1 -1
  13. package/crud/contentEntry/referenceFieldsMapping.js +5 -59
  14. package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
  15. package/crud/contentEntry.crud.js +27 -145
  16. package/crud/contentEntry.crud.js.map +1 -1
  17. package/crud/contentModel/afterCreate.js +0 -2
  18. package/crud/contentModel/afterCreate.js.map +1 -1
  19. package/crud/contentModel/afterCreateFrom.js +0 -2
  20. package/crud/contentModel/afterCreateFrom.js.map +1 -1
  21. package/crud/contentModel/afterDelete.js +0 -2
  22. package/crud/contentModel/afterDelete.js.map +1 -1
  23. package/crud/contentModel/afterUpdate.js +0 -2
  24. package/crud/contentModel/afterUpdate.js.map +1 -1
  25. package/crud/contentModel/beforeCreate.js +4 -32
  26. package/crud/contentModel/beforeCreate.js.map +1 -1
  27. package/crud/contentModel/beforeDelete.js +0 -10
  28. package/crud/contentModel/beforeDelete.js.map +1 -1
  29. package/crud/contentModel/beforeUpdate.js +0 -5
  30. package/crud/contentModel/beforeUpdate.js.map +1 -1
  31. package/crud/contentModel/contentModelManagerFactory.js +0 -7
  32. package/crud/contentModel/contentModelManagerFactory.js.map +1 -1
  33. package/crud/contentModel/createFieldModels.js +0 -6
  34. package/crud/contentModel/createFieldModels.js.map +1 -1
  35. package/crud/contentModel/createFieldStorageId.js +0 -2
  36. package/crud/contentModel/createFieldStorageId.js.map +1 -1
  37. package/crud/contentModel/fieldIdValidation.js +0 -5
  38. package/crud/contentModel/fieldIdValidation.js.map +1 -1
  39. package/crud/contentModel/idValidation.js +0 -5
  40. package/crud/contentModel/idValidation.js.map +1 -1
  41. package/crud/contentModel/models.js +1 -8
  42. package/crud/contentModel/models.js.map +1 -1
  43. package/crud/contentModel/systemFields.js.map +1 -1
  44. package/crud/contentModel/validateLayout.js +0 -8
  45. package/crud/contentModel/validateLayout.js.map +1 -1
  46. package/crud/contentModel/validateModel.js +0 -8
  47. package/crud/contentModel/validateModel.js.map +1 -1
  48. package/crud/contentModel/validateModelFields.js +8 -60
  49. package/crud/contentModel/validateModelFields.js.map +1 -1
  50. package/crud/contentModel.crud.js +25 -95
  51. package/crud/contentModel.crud.js.map +1 -1
  52. package/crud/contentModelGroup/beforeCreate.js +0 -12
  53. package/crud/contentModelGroup/beforeCreate.js.map +1 -1
  54. package/crud/contentModelGroup/beforeDelete.js +0 -8
  55. package/crud/contentModelGroup/beforeDelete.js.map +1 -1
  56. package/crud/contentModelGroup/beforeUpdate.js +0 -5
  57. package/crud/contentModelGroup/beforeUpdate.js.map +1 -1
  58. package/crud/contentModelGroup.crud.js +10 -47
  59. package/crud/contentModelGroup.crud.js.map +1 -1
  60. package/crud/index.js +0 -16
  61. package/crud/index.js.map +1 -1
  62. package/crud/settings.crud.js +0 -12
  63. package/crud/settings.crud.js.map +1 -1
  64. package/crud/system.crud.js +2 -37
  65. package/crud/system.crud.js.map +1 -1
  66. package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +0 -13
  67. package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js.map +1 -1
  68. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +0 -53
  69. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
  70. package/fieldConverters/index.js +0 -4
  71. package/fieldConverters/index.js.map +1 -1
  72. package/graphql/buildSchemaPlugins.js +5 -9
  73. package/graphql/buildSchemaPlugins.js.map +1 -1
  74. package/graphql/graphQLHandlerFactory.js +3 -28
  75. package/graphql/graphQLHandlerFactory.js.map +1 -1
  76. package/graphql/index.js +1 -8
  77. package/graphql/index.js.map +1 -1
  78. package/graphql/schema/baseContentSchema.js +3 -11
  79. package/graphql/schema/baseContentSchema.js.map +1 -1
  80. package/graphql/schema/contentEntries.js +2 -42
  81. package/graphql/schema/contentEntries.js.map +1 -1
  82. package/graphql/schema/contentModelGroups.js +2 -19
  83. package/graphql/schema/contentModelGroups.js.map +1 -1
  84. package/graphql/schema/contentModels.js +20 -17
  85. package/graphql/schema/contentModels.js.map +1 -1
  86. package/graphql/schema/createFieldResolvers.js +3 -21
  87. package/graphql/schema/createFieldResolvers.js.map +1 -1
  88. package/graphql/schema/createManageResolvers.js +0 -26
  89. package/graphql/schema/createManageResolvers.js.map +1 -1
  90. package/graphql/schema/createManageSDL.js +1 -14
  91. package/graphql/schema/createManageSDL.js.map +1 -1
  92. package/graphql/schema/createPreviewResolvers.js +0 -10
  93. package/graphql/schema/createPreviewResolvers.js.map +1 -1
  94. package/graphql/schema/createReadResolvers.js +0 -10
  95. package/graphql/schema/createReadResolvers.js.map +1 -1
  96. package/graphql/schema/createReadSDL.js +0 -10
  97. package/graphql/schema/createReadSDL.js.map +1 -1
  98. package/graphql/schema/resolvers/commonFieldResolvers.js +0 -2
  99. package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -1
  100. package/graphql/schema/resolvers/manage/resolveCreate.js +0 -3
  101. package/graphql/schema/resolvers/manage/resolveCreate.js.map +1 -1
  102. package/graphql/schema/resolvers/manage/resolveCreateFrom.js +0 -3
  103. package/graphql/schema/resolvers/manage/resolveCreateFrom.js.map +1 -1
  104. package/graphql/schema/resolvers/manage/resolveDelete.js +0 -6
  105. package/graphql/schema/resolvers/manage/resolveDelete.js.map +1 -1
  106. package/graphql/schema/resolvers/manage/resolveGet.js +0 -16
  107. package/graphql/schema/resolvers/manage/resolveGet.js.map +1 -1
  108. package/graphql/schema/resolvers/manage/resolveGetByIds.js +0 -3
  109. package/graphql/schema/resolvers/manage/resolveGetByIds.js.map +1 -1
  110. package/graphql/schema/resolvers/manage/resolveGetRevisions.js +0 -3
  111. package/graphql/schema/resolvers/manage/resolveGetRevisions.js.map +1 -1
  112. package/graphql/schema/resolvers/manage/resolveList.js +0 -3
  113. package/graphql/schema/resolvers/manage/resolveList.js.map +1 -1
  114. package/graphql/schema/resolvers/manage/resolvePublish.js +0 -3
  115. package/graphql/schema/resolvers/manage/resolvePublish.js.map +1 -1
  116. package/graphql/schema/resolvers/manage/resolveRepublish.js +0 -3
  117. package/graphql/schema/resolvers/manage/resolveRepublish.js.map +1 -1
  118. package/graphql/schema/resolvers/manage/resolveUnpublish.js +0 -3
  119. package/graphql/schema/resolvers/manage/resolveUnpublish.js.map +1 -1
  120. package/graphql/schema/resolvers/manage/resolveUpdate.js +0 -3
  121. package/graphql/schema/resolvers/manage/resolveUpdate.js.map +1 -1
  122. package/graphql/schema/resolvers/preview/resolveGet.js +0 -8
  123. package/graphql/schema/resolvers/preview/resolveGet.js.map +1 -1
  124. package/graphql/schema/resolvers/preview/resolveList.js +0 -3
  125. package/graphql/schema/resolvers/preview/resolveList.js.map +1 -1
  126. package/graphql/schema/resolvers/read/resolveGet.js +0 -8
  127. package/graphql/schema/resolvers/read/resolveGet.js.map +1 -1
  128. package/graphql/schema/resolvers/read/resolveList.js +0 -3
  129. package/graphql/schema/resolvers/read/resolveList.js.map +1 -1
  130. package/graphql/schema/schemaPlugins.js +5 -19
  131. package/graphql/schema/schemaPlugins.js.map +1 -1
  132. package/graphql/system.js +1 -14
  133. package/graphql/system.js.map +1 -1
  134. package/graphqlFields/boolean.js +0 -12
  135. package/graphqlFields/boolean.js.map +1 -1
  136. package/graphqlFields/datetime.js +0 -17
  137. package/graphqlFields/datetime.js.map +1 -1
  138. package/graphqlFields/file.js +0 -8
  139. package/graphqlFields/file.js.map +1 -1
  140. package/graphqlFields/helpers.js +0 -10
  141. package/graphqlFields/helpers.js.map +1 -1
  142. package/graphqlFields/index.js +0 -11
  143. package/graphqlFields/index.js.map +1 -1
  144. package/graphqlFields/longText.js +0 -10
  145. package/graphqlFields/longText.js.map +1 -1
  146. package/graphqlFields/number.js +0 -12
  147. package/graphqlFields/number.js.map +1 -1
  148. package/graphqlFields/object.js +6 -36
  149. package/graphqlFields/object.js.map +1 -1
  150. package/graphqlFields/ref.js +17 -51
  151. package/graphqlFields/ref.js.map +1 -1
  152. package/graphqlFields/richText.js +0 -9
  153. package/graphqlFields/richText.js.map +1 -1
  154. package/graphqlFields/text.js +0 -11
  155. package/graphqlFields/text.js.map +1 -1
  156. package/index.js +0 -19
  157. package/index.js.map +1 -1
  158. package/modelManager/DefaultCmsModelManager.js +0 -16
  159. package/modelManager/DefaultCmsModelManager.js.map +1 -1
  160. package/modelManager/index.js +0 -4
  161. package/modelManager/index.js.map +1 -1
  162. package/package.json +24 -25
  163. package/parameters/context.js +0 -4
  164. package/parameters/context.js.map +1 -1
  165. package/parameters/header.js +0 -11
  166. package/parameters/header.js.map +1 -1
  167. package/parameters/index.js +0 -8
  168. package/parameters/index.js.map +1 -1
  169. package/parameters/manual.js +1 -8
  170. package/parameters/manual.js.map +1 -1
  171. package/parameters/path.js +0 -11
  172. package/parameters/path.js.map +1 -1
  173. package/plugins/CmsGroupPlugin.js +0 -8
  174. package/plugins/CmsGroupPlugin.js.map +1 -1
  175. package/plugins/CmsModelFieldConverterPlugin.js +0 -5
  176. package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
  177. package/plugins/CmsModelPlugin.js +2 -38
  178. package/plugins/CmsModelPlugin.js.map +1 -1
  179. package/plugins/CmsParametersPlugin.js +0 -7
  180. package/plugins/CmsParametersPlugin.js.map +1 -1
  181. package/plugins/StorageTransformPlugin.js +0 -9
  182. package/plugins/StorageTransformPlugin.js.map +1 -1
  183. package/plugins/index.js +0 -10
  184. package/plugins/index.js.map +1 -1
  185. package/storage/default.js +0 -3
  186. package/storage/default.js.map +1 -1
  187. package/storage/object.js +0 -18
  188. package/storage/object.js.map +1 -1
  189. package/types.d.ts +14 -3
  190. package/types.js +0 -62
  191. package/types.js.map +1 -1
  192. package/upgrades/5.33.0/index.js +3 -26
  193. package/upgrades/5.33.0/index.js.map +1 -1
  194. package/upgrades/index.js +0 -3
  195. package/upgrades/index.js.map +1 -1
  196. package/utils/access.js +11 -25
  197. package/utils/access.js.map +1 -1
  198. package/utils/converters/Converter.js +0 -13
  199. package/utils/converters/Converter.js.map +1 -1
  200. package/utils/converters/ConverterCollection.d.ts +7 -0
  201. package/utils/converters/ConverterCollection.js +27 -24
  202. package/utils/converters/ConverterCollection.js.map +1 -1
  203. package/utils/converters/valueKeyStorageConverter.js +0 -26
  204. package/utils/converters/valueKeyStorageConverter.js.map +1 -1
  205. package/utils/createTypeName.js +0 -8
  206. package/utils/createTypeName.js.map +1 -1
  207. package/utils/entryStorage.js +10 -26
  208. package/utils/entryStorage.js.map +1 -1
  209. package/utils/filterAsync.js +0 -5
  210. package/utils/filterAsync.js.map +1 -1
  211. package/utils/filterModelFields.js +3 -9
  212. package/utils/filterModelFields.js.map +1 -1
  213. package/utils/getEntryTitle.js +0 -9
  214. package/utils/getEntryTitle.js.map +1 -1
  215. package/utils/getSchemaFromFieldPlugins.js +2 -6
  216. package/utils/getSchemaFromFieldPlugins.js.map +1 -1
  217. package/utils/ownership.js +0 -8
  218. package/utils/ownership.js.map +1 -1
  219. package/utils/permissions.js +8 -23
  220. package/utils/permissions.js.map +1 -1
  221. package/utils/pluralizedTypeName.js +0 -6
  222. package/utils/pluralizedTypeName.js.map +1 -1
  223. package/utils/renderFields.js +0 -8
  224. package/utils/renderFields.js.map +1 -1
  225. package/utils/renderGetFilterFields.js +0 -11
  226. package/utils/renderGetFilterFields.js.map +1 -1
  227. package/utils/renderInputFields.js +0 -8
  228. package/utils/renderInputFields.js.map +1 -1
  229. package/utils/renderListFilterFields.js +1 -9
  230. package/utils/renderListFilterFields.js.map +1 -1
  231. package/utils/renderSortEnum.js +0 -7
  232. package/utils/renderSortEnum.js.map +1 -1
  233. package/utils/toSlug.js +0 -4
  234. package/utils/toSlug.js.map +1 -1
  235. package/validators/dateGte.js +0 -7
  236. package/validators/dateGte.js.map +1 -1
  237. package/validators/dateLte.js +0 -7
  238. package/validators/dateLte.js.map +1 -1
  239. package/validators/gte.js +0 -8
  240. package/validators/gte.js.map +1 -1
  241. package/validators/in.js +0 -8
  242. package/validators/in.js.map +1 -1
  243. package/validators/index.js +0 -15
  244. package/validators/index.js.map +1 -1
  245. package/validators/lte.js +0 -8
  246. package/validators/lte.js.map +1 -1
  247. package/validators/maxLength.js +0 -8
  248. package/validators/maxLength.js.map +1 -1
  249. package/validators/minLength.js +0 -8
  250. package/validators/minLength.js.map +1 -1
  251. package/validators/pattern.js +0 -9
  252. package/validators/pattern.js.map +1 -1
  253. package/validators/patternPlugins/email.js +0 -2
  254. package/validators/patternPlugins/email.js.map +1 -1
  255. package/validators/patternPlugins/index.js +0 -8
  256. package/validators/patternPlugins/index.js.map +1 -1
  257. package/validators/patternPlugins/lowerCase.js +0 -2
  258. package/validators/patternPlugins/lowerCase.js.map +1 -1
  259. package/validators/patternPlugins/lowerCaseSpace.js +0 -2
  260. package/validators/patternPlugins/lowerCaseSpace.js.map +1 -1
  261. package/validators/patternPlugins/upperCase.js +0 -2
  262. package/validators/patternPlugins/upperCase.js.map +1 -1
  263. package/validators/patternPlugins/upperCaseSpace.js +0 -2
  264. package/validators/patternPlugins/upperCaseSpace.js.map +1 -1
  265. package/validators/patternPlugins/url.js +0 -2
  266. package/validators/patternPlugins/url.js.map +1 -1
  267. package/validators/required.js +0 -5
  268. package/validators/required.js.map +1 -1
  269. package/validators/timeGte.js +0 -8
  270. package/validators/timeGte.js.map +1 -1
  271. package/validators/timeLte.js +0 -8
  272. package/validators/timeLte.js.map +1 -1
  273. package/validators/unique.js +0 -7
  274. package/validators/unique.js.map +1 -1
@@ -4,33 +4,25 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.validateLayout = void 0;
7
-
8
7
  const validateLayout = (layout, fields = []) => {
9
8
  const flatLayoutIdList = layout.reduce((acc, id) => {
10
9
  return acc.concat(Array.isArray(id) ? id : [id]);
11
10
  }, []);
12
-
13
11
  if (flatLayoutIdList.length !== fields.length) {
14
12
  throw new Error(`There are ${flatLayoutIdList.length} IDs in the layout and ${fields.length} in fields, which cannot be - numbers must be the same.`);
15
13
  }
16
-
17
14
  for (const field of fields) {
18
15
  if (flatLayoutIdList.includes(field.id)) {
19
16
  continue;
20
17
  }
21
-
22
18
  throw new Error(`Field "${field.id}" is not defined in layout.`);
23
19
  }
24
-
25
20
  for (const id of flatLayoutIdList) {
26
21
  const fieldFound = fields.some(f => f.id === id);
27
-
28
22
  if (fieldFound) {
29
23
  continue;
30
24
  }
31
-
32
25
  throw new Error(`Field id "${id}" is in layout but not in fields.`);
33
26
  }
34
27
  };
35
-
36
28
  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,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
+ {"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,32 +1,24 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.validateModel = void 0;
9
-
10
8
  var _error = _interopRequireDefault(require("@webiny/error"));
11
-
12
9
  var _CmsModelPlugin = require("../../plugins/CmsModelPlugin");
13
-
14
10
  var _validateModelFields = require("./validateModelFields");
15
-
16
11
  const validateModel = params => {
17
12
  const {
18
13
  model,
19
14
  plugins
20
15
  } = params;
21
16
  const modelPlugin = plugins.byType(_CmsModelPlugin.CmsModelPlugin.type).find(item => item.contentModel.modelId === model.modelId);
22
-
23
17
  if (modelPlugin) {
24
18
  throw new _error.default("Content models defined via plugins cannot be updated.", "CONTENT_MODEL_UPDATE_ERROR", {
25
19
  modelId: model.modelId
26
20
  });
27
21
  }
28
-
29
22
  (0, _validateModelFields.validateModelFields)(params);
30
23
  };
31
-
32
24
  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,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
+ {"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,25 +1,17 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.validateModelFields = void 0;
9
-
10
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
9
  var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
10
  var _createManageSDL = require("../../graphql/schema/createManageSDL");
15
-
16
11
  var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
17
-
18
12
  var _createFieldStorageId = require("./createFieldStorageId");
19
-
20
13
  const defaultTitleFieldId = "id";
21
14
  const allowedTitleFieldTypes = ["text", "number"];
22
-
23
15
  const getContentModelTitleFieldId = (fields, titleFieldId) => {
24
16
  /**
25
17
  * If there are no fields defined, we will return the default field
@@ -32,8 +24,6 @@ const getContentModelTitleFieldId = (fields, titleFieldId) => {
32
24
  * we will take first text field that has no multiple values enabled
33
25
  * or if initial titleFieldId is the default one also try to find first available text field
34
26
  */
35
-
36
-
37
27
  if (!titleFieldId || titleFieldId === defaultTitleFieldId) {
38
28
  const titleField = fields.find(field => {
39
29
  return field.type === "text" && !field.multipleValues;
@@ -45,17 +35,13 @@ const getContentModelTitleFieldId = (fields, titleFieldId) => {
45
35
  * for correct type
46
36
  * and that it is not multiple values field
47
37
  */
48
-
49
-
50
38
  const target = fields.find(f => f.fieldId === titleFieldId);
51
-
52
39
  if (!target) {
53
40
  throw new _error.default(`Field selected for the title field does not exist in the model.`, "VALIDATION_ERROR", {
54
41
  fieldId: titleFieldId,
55
42
  fields
56
43
  });
57
44
  }
58
-
59
45
  if (allowedTitleFieldTypes.includes(target.type) === false) {
60
46
  throw new _error.default(`Only ${allowedTitleFieldTypes.join(", ")} and id fields can be used as an entry title.`, "ENTRY_TITLE_FIELD_TYPE", {
61
47
  storageId: target.storageId,
@@ -63,7 +49,6 @@ const getContentModelTitleFieldId = (fields, titleFieldId) => {
63
49
  type: target.type
64
50
  });
65
51
  }
66
-
67
52
  if (target.multipleValues) {
68
53
  throw new _error.default(`Fields that accept multiple values cannot be used as the entry title.`, "ENTRY_TITLE_FIELD_TYPE", {
69
54
  storageId: target.storageId,
@@ -71,18 +56,15 @@ const getContentModelTitleFieldId = (fields, titleFieldId) => {
71
56
  type: target.type
72
57
  });
73
58
  }
74
-
75
59
  return target.fieldId;
76
60
  };
77
-
78
61
  const extractInvalidField = (model, err) => {
79
62
  var _err$source;
80
-
81
63
  const sdl = ((_err$source = err.source) === null || _err$source === void 0 ? void 0 : _err$source.body) || "";
64
+
82
65
  /**
83
66
  * Find the invalid type
84
67
  */
85
-
86
68
  const {
87
69
  line: lineNumber
88
70
  } = err.locations ? err.locations[0] : {
@@ -91,33 +73,25 @@ const extractInvalidField = (model, err) => {
91
73
  const sdlLines = sdl.split("\n");
92
74
  let sdlLine;
93
75
  let gqlType;
94
-
95
76
  for (let i = lineNumber; i > 0; i--) {
96
77
  if (sdlLine && sdlLine.includes("type ")) {
97
78
  gqlType = sdlLine.match(/type\s+(.*?)\s+{/);
98
79
  break;
99
80
  }
100
-
101
81
  sdlLine = sdlLines[i];
102
82
  }
103
-
104
83
  let invalidField = undefined;
105
-
106
84
  if (Array.isArray(gqlType)) {
107
85
  const fieldRegex = new RegExp(`([^\\s+].*?):\\s+\\[?${gqlType[1]}!?\\]?`);
108
86
  const matched = sdl.match(fieldRegex);
109
-
110
87
  if (matched) {
111
88
  invalidField = matched[1];
112
89
  }
113
90
  }
114
-
115
91
  let message = `See more details in the browser console.`;
116
-
117
92
  if (invalidField) {
118
93
  message = `Please review the definition of "${invalidField}" field.`;
119
94
  }
120
-
121
95
  return {
122
96
  data: {
123
97
  modelId: model.modelId,
@@ -128,7 +102,6 @@ const extractInvalidField = (model, err) => {
128
102
  message: [`Model "${model.modelId}" was not saved!`, message].join("\n")
129
103
  };
130
104
  };
131
-
132
105
  const validateFields = params => {
133
106
  const {
134
107
  plugins,
@@ -138,21 +111,16 @@ const validateFields = params => {
138
111
  } = params;
139
112
  const fieldIdList = [];
140
113
  const storageIdList = [];
141
-
142
114
  for (const field of fields) {
143
115
  var _field$settings, _originalField$settin;
144
-
145
116
  const plugin = plugins.find(item => item.fieldType === field.type);
146
-
147
117
  if (!plugin) {
148
118
  throw new Error(`Cannot update content model because of the unknown "${field.type}" field.`);
149
119
  }
150
-
151
120
  const originalField = originalFields.find(f => f.id === field.id);
152
121
  /**
153
122
  * Field MUST have an fieldId defined.
154
123
  */
155
-
156
124
  if (!field.fieldId) {
157
125
  throw new _error.default(`Field does not have an "fieldId" defined.`, "MISSING_FIELD_ID", {
158
126
  field
@@ -171,12 +139,9 @@ const validateFields = params => {
171
139
  * https://discuss.elastic.co/t/special-characters-in-field-names/10658/3
172
140
  * https://discuss.elastic.co/t/illegal-characters-in-elasticsearch-field-names/17196/2
173
141
  */
174
-
175
-
176
142
  const isLocked = lockedFields.some(lockedField => {
177
143
  return lockedField.fieldId === field.storageId;
178
144
  });
179
-
180
145
  if (!field.storageId) {
181
146
  /**
182
147
  * In case field is locked, we must set the storageId to the fieldId value.
@@ -205,44 +170,35 @@ const validateFields = params => {
205
170
  * Check the field's fieldId against existing ones.
206
171
  * There cannot be two fields with the same fieldId - outside world identifier.
207
172
  */
208
-
209
-
210
173
  if (fieldIdList.includes(field.fieldId)) {
211
174
  throw new _error.default(`Cannot update content model because field "${field.storageId}" has fieldId "${field.fieldId}", which is already used.`);
212
175
  }
213
-
214
176
  fieldIdList.push(field.fieldId);
215
177
  /**
216
178
  * Check the field's storageId against the existing ones.
217
179
  * There cannot be two fields with the same storageId.
218
180
  */
219
-
220
181
  if (storageIdList.includes(field.storageId)) {
221
182
  throw new _error.default(`Cannot update content model because field "${field.label}" has storageId "${field.storageId}", which is already used.`);
222
183
  }
223
-
224
184
  storageIdList.push(field.storageId);
225
185
  /**
226
186
  * TODO maybe make this part pluginable?
227
187
  * We need to check the object field child fields.
228
188
  * It must be recursive.
229
189
  */
230
-
231
190
  if (field.type !== "object") {
232
191
  continue;
233
192
  }
234
-
235
193
  const childFields = ((_field$settings = field.settings) === null || _field$settings === void 0 ? void 0 : _field$settings.fields) || [];
236
194
  const originalChildFields = (originalField === null || originalField === void 0 ? void 0 : (_originalField$settin = originalField.settings) === null || _originalField$settin === void 0 ? void 0 : _originalField$settin.fields) || [];
237
195
  /**
238
196
  * No point in going further if there are no child fields.
239
197
  * Code will break if child fields were removed but used in the entries.
240
198
  */
241
-
242
199
  if (childFields.length === 0) {
243
200
  continue;
244
201
  }
245
-
246
202
  validateFields({
247
203
  fields: childFields,
248
204
  originalFields: originalChildFields,
@@ -251,7 +207,6 @@ const validateFields = params => {
251
207
  });
252
208
  }
253
209
  };
254
-
255
210
  const validateModelFields = params => {
256
211
  const {
257
212
  model,
@@ -261,19 +216,19 @@ const validateModelFields = params => {
261
216
  const {
262
217
  titleFieldId
263
218
  } = model;
219
+
264
220
  /**
265
221
  * There should be fields/locked fields in either model or data to be updated.
266
222
  */
267
-
268
223
  const {
269
224
  fields = [],
270
225
  lockedFields = []
271
226
  } = model;
227
+
272
228
  /**
273
229
  * Let's inspect the fields of the received content model. We prevent saving of a content model if it
274
230
  * contains a field for which a "cms-model-field-to-graphql" plugin does not exist on the backend.
275
231
  */
276
-
277
232
  const fieldTypePlugins = plugins.byType("cms-model-field-to-graphql");
278
233
  validateFields({
279
234
  fields,
@@ -281,7 +236,6 @@ const validateModelFields = params => {
281
236
  lockedFields,
282
237
  plugins: fieldTypePlugins
283
238
  });
284
-
285
239
  if (fields.length) {
286
240
  /**
287
241
  * Make sure that this model can be safely converted to a GraphQL SDL
@@ -292,30 +246,29 @@ const validateModelFields = params => {
292
246
  [pl.fieldType]: pl
293
247
  }), {})
294
248
  });
295
-
296
249
  try {
297
250
  (0, _graphqlTag.default)(schema);
298
251
  } catch (err) {
299
252
  throw new _error.default(extractInvalidField(model, err));
300
253
  }
301
254
  }
302
-
303
255
  model.titleFieldId = getContentModelTitleFieldId(fields, titleFieldId);
304
256
  const cmsLockedFieldPlugins = plugins.byType("cms-model-locked-field");
257
+
305
258
  /**
306
259
  * We must not allow removal or changes in fields that are already in use in content entries.
307
260
  * Locked fields still have fieldId (should be storageId) because of the old existing locked fields in the models.
308
261
  */
309
-
310
262
  for (const lockedField of lockedFields) {
311
263
  const existingField = fields.find(item => item.storageId === lockedField.fieldId);
264
+
312
265
  /**
313
266
  * Starting with 5.33.0 fields can be deleted.
314
267
  * Our UI gives a warning upon locked field deletion, but if user is managing fields through API directly - we cannot do anything.
315
268
  */
316
-
317
269
  if (!existingField) {
318
- continue; // throw new WebinyError(
270
+ continue;
271
+ // throw new WebinyError(
319
272
  // `Cannot remove the field "${lockedField.fieldId}" because it's already in use in created content.`,
320
273
  // "ENTRY_FIELD_USED",
321
274
  // {
@@ -330,24 +283,20 @@ const validateModelFields = params => {
330
283
  field: existingField
331
284
  });
332
285
  }
333
-
334
286
  if (lockedField.type !== existingField.type) {
335
287
  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", {
336
288
  field: existingField
337
289
  });
338
290
  }
291
+
339
292
  /**
340
293
  * Check `lockedField` invariant for specific field
341
294
  */
342
-
343
-
344
295
  const lockedFieldsByType = cmsLockedFieldPlugins.filter(pl => pl.fieldType === lockedField.type);
345
-
346
296
  for (const plugin of lockedFieldsByType) {
347
297
  if (typeof plugin.checkLockedField !== "function") {
348
298
  continue;
349
299
  }
350
-
351
300
  plugin.checkLockedField({
352
301
  lockedField,
353
302
  field: existingField
@@ -355,5 +304,4 @@ const validateModelFields = params => {
355
304
  }
356
305
  }
357
306
  };
358
-
359
307
  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;;AA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AAI,OAAO3B,MAAM,CAAC6B,gBAAd,KAAmC,UAAvC,EAAmD;QAC/C;MACH;;MACD7B,MAAM,CAAC6B,gBAAP,CAAwB;QACpBrB,WADoB;QAEpBnD,KAAK,EAAEqE;MAFa,CAAxB;IAIH;EACJ;AACJ,CA3GM"}
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,IAAI;AAEhC,MAAMC,sBAAsB,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC;AAEjD,MAAMC,2BAA2B,GAAG,CAACC,MAAuB,EAAEC,YAAqB,KAAa;EAC5F;AACJ;AACA;EACI,IAAID,MAAM,CAACE,MAAM,KAAK,CAAC,EAAE;IACrB,OAAOL,mBAAm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