@webiny/api-headless-cms 5.39.0-beta.0 → 5.39.0-beta.2

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 (250) hide show
  1. package/constants.d.ts +31 -0
  2. package/constants.js +48 -1
  3. package/constants.js.map +1 -1
  4. package/context.js +40 -34
  5. package/context.js.map +1 -1
  6. package/crud/contentEntry/entryDataFactories/createEntryData.d.ts +20 -0
  7. package/crud/contentEntry/entryDataFactories/createEntryData.js +228 -0
  8. package/crud/contentEntry/entryDataFactories/createEntryData.js.map +1 -0
  9. package/crud/contentEntry/entryDataFactories/createEntryRevisionFromData.d.ts +21 -0
  10. package/crud/contentEntry/entryDataFactories/createEntryRevisionFromData.js +114 -0
  11. package/crud/contentEntry/entryDataFactories/createEntryRevisionFromData.js.map +1 -0
  12. package/crud/contentEntry/entryDataFactories/createPublishEntryData.d.ts +13 -0
  13. package/crud/contentEntry/entryDataFactories/createPublishEntryData.js +61 -0
  14. package/crud/contentEntry/entryDataFactories/createPublishEntryData.js.map +1 -0
  15. package/crud/contentEntry/entryDataFactories/createRepublishEntryData.d.ts +12 -0
  16. package/crud/contentEntry/entryDataFactories/createRepublishEntryData.js +57 -0
  17. package/crud/contentEntry/entryDataFactories/createRepublishEntryData.js.map +1 -0
  18. package/crud/contentEntry/entryDataFactories/createUnpublishEntryData.d.ts +12 -0
  19. package/crud/contentEntry/entryDataFactories/createUnpublishEntryData.js +38 -0
  20. package/crud/contentEntry/entryDataFactories/createUnpublishEntryData.js.map +1 -0
  21. package/crud/contentEntry/entryDataFactories/createUpdateEntryData.d.ts +20 -0
  22. package/crud/contentEntry/entryDataFactories/createUpdateEntryData.js +122 -0
  23. package/crud/contentEntry/entryDataFactories/createUpdateEntryData.js.map +1 -0
  24. package/crud/contentEntry/entryDataFactories/index.d.ts +8 -0
  25. package/crud/contentEntry/entryDataFactories/index.js +95 -0
  26. package/crud/contentEntry/entryDataFactories/index.js.map +1 -0
  27. package/crud/contentEntry/entryDataFactories/mapAndCleanUpdatedInputData.d.ts +5 -0
  28. package/crud/contentEntry/entryDataFactories/mapAndCleanUpdatedInputData.js +36 -0
  29. package/crud/contentEntry/entryDataFactories/mapAndCleanUpdatedInputData.js.map +1 -0
  30. package/crud/contentEntry/entryDataFactories/statuses.d.ts +4 -0
  31. package/crud/contentEntry/entryDataFactories/statuses.js +15 -0
  32. package/crud/contentEntry/entryDataFactories/statuses.js.map +1 -0
  33. package/crud/contentEntry/entryDataValidation.js +29 -24
  34. package/crud/contentEntry/entryDataValidation.js.map +1 -1
  35. package/crud/contentEntry/markLockedFields.js +14 -9
  36. package/crud/contentEntry/markLockedFields.js.map +1 -1
  37. package/crud/contentEntry/referenceFieldsMapping.js +10 -12
  38. package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
  39. package/crud/contentEntry/searchableFields.js +2 -3
  40. package/crud/contentEntry/searchableFields.js.map +1 -1
  41. package/crud/contentEntry.crud.d.ts +1 -4
  42. package/crud/contentEntry.crud.js +140 -383
  43. package/crud/contentEntry.crud.js.map +1 -1
  44. package/crud/contentModel/fields/descriptionField.js +1 -1
  45. package/crud/contentModel/fields/descriptionField.js.map +1 -1
  46. package/crud/contentModel/fields/imageField.js +3 -7
  47. package/crud/contentModel/fields/imageField.js.map +1 -1
  48. package/crud/contentModel/fields/titleField.js +1 -1
  49. package/crud/contentModel/fields/titleField.js.map +1 -1
  50. package/crud/contentModel/listModelsFromDatabase.js +3 -4
  51. package/crud/contentModel/listModelsFromDatabase.js.map +1 -1
  52. package/crud/contentModel/validateModelFields.js +4 -5
  53. package/crud/contentModel/validateModelFields.js.map +1 -1
  54. package/crud/contentModel/validation.d.ts +96 -96
  55. package/crud/contentModel.crud.js +28 -26
  56. package/crud/contentModel.crud.js.map +1 -1
  57. package/crud/contentModelGroup/validation.d.ts +1 -1
  58. package/crud/contentModelGroup.crud.js +18 -15
  59. package/crud/contentModelGroup.crud.js.map +1 -1
  60. package/crud/system.crud.js +4 -4
  61. package/crud/system.crud.js.map +1 -1
  62. package/export/crud/exporting.js +2 -3
  63. package/export/crud/exporting.js.map +1 -1
  64. package/export/crud/importing.js +3 -3
  65. package/export/crud/importing.js.map +1 -1
  66. package/export/crud/imports/importData.js +30 -3
  67. package/export/crud/imports/importData.js.map +1 -1
  68. package/export/crud/imports/importGroups.js +15 -10
  69. package/export/crud/imports/importGroups.js.map +1 -1
  70. package/export/crud/imports/importModels.js +14 -12
  71. package/export/crud/imports/importModels.js.map +1 -1
  72. package/export/crud/imports/validateGroups.js +13 -7
  73. package/export/crud/imports/validateGroups.js.map +1 -1
  74. package/export/crud/imports/validateInput.js +15 -9
  75. package/export/crud/imports/validateInput.js.map +1 -1
  76. package/export/crud/imports/validateModels.d.ts +4 -1
  77. package/export/crud/imports/validateModels.js +24 -25
  78. package/export/crud/imports/validateModels.js.map +1 -1
  79. package/export/types.d.ts +2 -0
  80. package/export/types.js.map +1 -1
  81. package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +1 -6
  82. package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js.map +1 -1
  83. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +2 -7
  84. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -1
  85. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +44 -37
  86. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
  87. package/graphql/getSchema.js +15 -9
  88. package/graphql/getSchema.js.map +1 -1
  89. package/graphql/index.d.ts +1 -1
  90. package/graphql/schema/baseContentSchema.js +6 -7
  91. package/graphql/schema/baseContentSchema.js.map +1 -1
  92. package/graphql/schema/baseSchema.js +1 -8
  93. package/graphql/schema/baseSchema.js.map +1 -1
  94. package/graphql/schema/contentEntries.js +44 -13
  95. package/graphql/schema/contentEntries.js.map +1 -1
  96. package/graphql/schema/contentModelGroups.js +1 -1
  97. package/graphql/schema/contentModelGroups.js.map +1 -1
  98. package/graphql/schema/contentModels.js +5 -5
  99. package/graphql/schema/contentModels.js.map +1 -1
  100. package/graphql/schema/createFieldResolvers.js +11 -11
  101. package/graphql/schema/createFieldResolvers.js.map +1 -1
  102. package/graphql/schema/createManageResolvers.js +6 -9
  103. package/graphql/schema/createManageResolvers.js.map +1 -1
  104. package/graphql/schema/createManageSDL.js +30 -24
  105. package/graphql/schema/createManageSDL.js.map +1 -1
  106. package/graphql/schema/createPreviewResolvers.js +4 -5
  107. package/graphql/schema/createPreviewResolvers.js.map +1 -1
  108. package/graphql/schema/createReadResolvers.js +4 -5
  109. package/graphql/schema/createReadResolvers.js.map +1 -1
  110. package/graphql/schema/createReadSDL.js +9 -4
  111. package/graphql/schema/createReadSDL.js.map +1 -1
  112. package/graphql/schema/resolvers/manage/resolveDelete.js +1 -1
  113. package/graphql/schema/resolvers/manage/resolveDelete.js.map +1 -1
  114. package/graphql/schema/resolvers/manage/resolveDeleteMultiple.js +1 -1
  115. package/graphql/schema/resolvers/manage/resolveDeleteMultiple.js.map +1 -1
  116. package/graphql/schema/resolvers/manage/resolveGet.js +9 -4
  117. package/graphql/schema/resolvers/manage/resolveGet.js.map +1 -1
  118. package/graphql/schema/resolvers/manage/resolvePublish.d.ts +1 -2
  119. package/graphql/schema/resolvers/manage/resolvePublish.js +1 -1
  120. package/graphql/schema/resolvers/manage/resolvePublish.js.map +1 -1
  121. package/graphql/schema/resolvers/preview/resolveGet.js +3 -4
  122. package/graphql/schema/resolvers/preview/resolveGet.js.map +1 -1
  123. package/graphql/schema/resolvers/read/resolveGet.js +3 -4
  124. package/graphql/schema/resolvers/read/resolveGet.js.map +1 -1
  125. package/graphqlFields/datetime.js +1 -2
  126. package/graphqlFields/datetime.js.map +1 -1
  127. package/graphqlFields/dynamicZone/dynamicZoneField.js +13 -13
  128. package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -1
  129. package/graphqlFields/dynamicZone/dynamicZoneStorage.js +6 -6
  130. package/graphqlFields/dynamicZone/dynamicZoneStorage.js.map +1 -1
  131. package/graphqlFields/index.js +2 -1
  132. package/graphqlFields/index.js.map +1 -1
  133. package/graphqlFields/json.d.ts +2 -0
  134. package/graphqlFields/json.js +49 -0
  135. package/graphqlFields/json.js.map +1 -0
  136. package/graphqlFields/object.js +20 -28
  137. package/graphqlFields/object.js.map +1 -1
  138. package/graphqlFields/ref.js +24 -14
  139. package/graphqlFields/ref.js.map +1 -1
  140. package/graphqlFields/richText/RichTextPluginsProcessor.d.ts +6 -0
  141. package/graphqlFields/richText/RichTextPluginsProcessor.js +34 -0
  142. package/graphqlFields/richText/RichTextPluginsProcessor.js.map +1 -0
  143. package/graphqlFields/richText/richTextResolver.d.ts +7 -0
  144. package/graphqlFields/richText/richTextResolver.js +39 -0
  145. package/graphqlFields/richText/richTextResolver.js.map +1 -0
  146. package/graphqlFields/richText.js +8 -2
  147. package/graphqlFields/richText.js.map +1 -1
  148. package/htmlRenderer/LexicalRenderer.d.ts +5 -0
  149. package/htmlRenderer/LexicalRenderer.js +28 -0
  150. package/htmlRenderer/LexicalRenderer.js.map +1 -0
  151. package/htmlRenderer/createLexicalHTMLRenderer.d.ts +2 -0
  152. package/htmlRenderer/createLexicalHTMLRenderer.js +31 -0
  153. package/htmlRenderer/createLexicalHTMLRenderer.js.map +1 -0
  154. package/index.d.ts +1 -1
  155. package/index.js +4 -4
  156. package/index.js.map +1 -1
  157. package/modelManager/DefaultCmsModelManager.js +0 -4
  158. package/modelManager/DefaultCmsModelManager.js.map +1 -1
  159. package/package.json +21 -19
  160. package/parameters/context.js +1 -1
  161. package/parameters/context.js.map +1 -1
  162. package/parameters/header.js +1 -2
  163. package/parameters/header.js.map +1 -1
  164. package/parameters/manual.js +6 -3
  165. package/parameters/manual.js.map +1 -1
  166. package/parameters/path.js +1 -2
  167. package/parameters/path.js.map +1 -1
  168. package/plugins/CmsGraphQLSchemaPlugin.js +3 -4
  169. package/plugins/CmsGraphQLSchemaPlugin.js.map +1 -1
  170. package/plugins/CmsGraphQLSchemaSorterPlugin.js +1 -4
  171. package/plugins/CmsGraphQLSchemaSorterPlugin.js.map +1 -1
  172. package/plugins/CmsGroupPlugin.js +4 -7
  173. package/plugins/CmsGroupPlugin.js.map +1 -1
  174. package/plugins/CmsModelFieldConverterPlugin.js +3 -4
  175. package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
  176. package/plugins/CmsModelPlugin.d.ts +6 -4
  177. package/plugins/CmsModelPlugin.js +52 -27
  178. package/plugins/CmsModelPlugin.js.map +1 -1
  179. package/plugins/CmsParametersPlugin.js +1 -4
  180. package/plugins/CmsParametersPlugin.js.map +1 -1
  181. package/plugins/CmsRichTextRendererPlugin.d.ts +24 -0
  182. package/plugins/CmsRichTextRendererPlugin.js +28 -0
  183. package/plugins/CmsRichTextRendererPlugin.js.map +1 -0
  184. package/plugins/StorageOperationsCmsModelPlugin.js +3 -6
  185. package/plugins/StorageOperationsCmsModelPlugin.js.map +1 -1
  186. package/plugins/StorageTransformPlugin.d.ts +2 -2
  187. package/plugins/StorageTransformPlugin.js +1 -4
  188. package/plugins/StorageTransformPlugin.js.map +1 -1
  189. package/plugins/index.d.ts +1 -0
  190. package/plugins/index.js +11 -0
  191. package/plugins/index.js.map +1 -1
  192. package/storage/index.d.ts +1 -0
  193. package/storage/index.js +15 -0
  194. package/storage/index.js.map +1 -0
  195. package/storage/json.d.ts +2 -0
  196. package/storage/json.js +27 -0
  197. package/storage/json.js.map +1 -0
  198. package/storage/object.js +5 -7
  199. package/storage/object.js.map +1 -1
  200. package/types.d.ts +182 -53
  201. package/types.js +0 -3
  202. package/types.js.map +1 -1
  203. package/utils/access.d.ts +0 -1
  204. package/utils/access.js +1 -10
  205. package/utils/access.js.map +1 -1
  206. package/utils/caching/Cache.js +3 -5
  207. package/utils/caching/Cache.js.map +1 -1
  208. package/utils/caching/CacheKey.js +0 -3
  209. package/utils/caching/CacheKey.js.map +1 -1
  210. package/utils/converters/Converter.js +1 -4
  211. package/utils/converters/Converter.js.map +1 -1
  212. package/utils/converters/ConverterCollection.js +10 -6
  213. package/utils/converters/ConverterCollection.js.map +1 -1
  214. package/utils/converters/valueKeyStorageConverter.js +3 -3
  215. package/utils/converters/valueKeyStorageConverter.js.map +1 -1
  216. package/utils/date.d.ts +2 -2
  217. package/utils/date.js +1 -1
  218. package/utils/date.js.map +1 -1
  219. package/utils/entryStorage.js +3 -3
  220. package/utils/entryStorage.js.map +1 -1
  221. package/utils/identity.d.ts +2 -0
  222. package/utils/identity.js +20 -0
  223. package/utils/identity.js.map +1 -0
  224. package/utils/permissions/ModelsPermissions.js +0 -3
  225. package/utils/permissions/ModelsPermissions.js.map +1 -1
  226. package/utils/renderGetFilterFields.js +2 -3
  227. package/utils/renderGetFilterFields.js.map +1 -1
  228. package/utils/renderListFilterFields.js +9 -3
  229. package/utils/renderListFilterFields.js.map +1 -1
  230. package/utils/renderSortEnum.js +2 -1
  231. package/utils/renderSortEnum.js.map +1 -1
  232. package/validators/gte.js +1 -2
  233. package/validators/gte.js.map +1 -1
  234. package/validators/in.js +1 -2
  235. package/validators/in.js.map +1 -1
  236. package/validators/lte.js +1 -2
  237. package/validators/lte.js.map +1 -1
  238. package/validators/maxLength.js +1 -2
  239. package/validators/maxLength.js.map +1 -1
  240. package/validators/minLength.js +1 -2
  241. package/validators/minLength.js.map +1 -1
  242. package/validators/pattern.js +2 -2
  243. package/validators/pattern.js.map +1 -1
  244. package/validators/timeGte.js +1 -2
  245. package/validators/timeGte.js.map +1 -1
  246. package/validators/timeLte.js +1 -2
  247. package/validators/timeLte.js.map +1 -1
  248. package/graphql/schema/resolvers/commonFieldResolvers.d.ts +0 -7
  249. package/graphql/schema/resolvers/commonFieldResolvers.js +0 -15
  250. package/graphql/schema/resolvers/commonFieldResolvers.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-headless-cms",
3
- "version": "5.39.0-beta.0",
3
+ "version": "5.39.0-beta.2",
4
4
  "main": "index.js",
5
5
  "keywords": [
6
6
  "cms:base"
@@ -20,27 +20,29 @@
20
20
  "dependencies": {
21
21
  "@babel/runtime": "7.22.6",
22
22
  "@graphql-tools/schema": "7.1.5",
23
- "@webiny/api": "5.39.0-beta.0",
24
- "@webiny/api-i18n": "5.39.0-beta.0",
25
- "@webiny/api-security": "5.39.0-beta.0",
26
- "@webiny/api-tenancy": "5.39.0-beta.0",
27
- "@webiny/error": "5.39.0-beta.0",
28
- "@webiny/handler": "5.39.0-beta.0",
29
- "@webiny/handler-aws": "5.39.0-beta.0",
30
- "@webiny/handler-db": "5.39.0-beta.0",
31
- "@webiny/handler-graphql": "5.39.0-beta.0",
32
- "@webiny/plugins": "5.39.0-beta.0",
33
- "@webiny/pubsub": "5.39.0-beta.0",
34
- "@webiny/utils": "5.39.0-beta.0",
35
- "@webiny/validation": "5.39.0-beta.0",
23
+ "@webiny/api": "5.39.0-beta.2",
24
+ "@webiny/api-i18n": "5.39.0-beta.2",
25
+ "@webiny/api-security": "5.39.0-beta.2",
26
+ "@webiny/api-tenancy": "5.39.0-beta.2",
27
+ "@webiny/error": "5.39.0-beta.2",
28
+ "@webiny/handler": "5.39.0-beta.2",
29
+ "@webiny/handler-aws": "5.39.0-beta.2",
30
+ "@webiny/handler-db": "5.39.0-beta.2",
31
+ "@webiny/handler-graphql": "5.39.0-beta.2",
32
+ "@webiny/lexical-converter": "5.39.0-beta.2",
33
+ "@webiny/plugins": "5.39.0-beta.2",
34
+ "@webiny/pubsub": "5.39.0-beta.2",
35
+ "@webiny/utils": "5.39.0-beta.2",
36
+ "@webiny/validation": "5.39.0-beta.2",
36
37
  "code-frame": "5.0.0",
37
38
  "dot-prop": "6.0.1",
38
39
  "graphql-tag": "2.12.6",
40
+ "jsdom": "21.1.2",
39
41
  "lodash": "4.17.21",
40
42
  "p-map": "4.0.0",
41
43
  "p-reduce": "2.1.0",
42
44
  "pluralize": "8.0.0",
43
- "semver": "6.3.0",
45
+ "semver": "7.5.4",
44
46
  "slugify": "1.6.5",
45
47
  "zod": "3.21.4"
46
48
  },
@@ -48,9 +50,9 @@
48
50
  "@babel/cli": "7.22.6",
49
51
  "@babel/core": "7.22.8",
50
52
  "@babel/preset-env": "7.22.7",
51
- "@webiny/api-wcp": "5.39.0-beta.0",
52
- "@webiny/cli": "5.39.0-beta.0",
53
- "@webiny/project-utils": "5.39.0-beta.0",
53
+ "@webiny/api-wcp": "5.39.0-beta.2",
54
+ "@webiny/cli": "5.39.0-beta.2",
55
+ "@webiny/project-utils": "5.39.0-beta.2",
54
56
  "apollo-graphql": "0.9.7",
55
57
  "get-yarn-workspaces": "1.0.2",
56
58
  "graphql": "15.8.0",
@@ -70,5 +72,5 @@
70
72
  "build": "yarn webiny run build",
71
73
  "watch": "yarn webiny run watch"
72
74
  },
73
- "gitHead": "df94742fba6658ed3507e1e17ab53dc77bb66330"
75
+ "gitHead": "193039382160557448f23f43685f29136f58f87a"
74
76
  }
@@ -10,7 +10,7 @@ const createContextParameterPlugin = () => {
10
10
  return new _CmsParametersPlugin.CmsParametersPlugin(async context => {
11
11
  const locale = context.i18n.getContentLocale();
12
12
  return {
13
- locale: (locale === null || locale === void 0 ? void 0 : locale.code) || DEFAULT_LOCALE_CODE,
13
+ locale: locale?.code || DEFAULT_LOCALE_CODE,
14
14
  type: null
15
15
  };
16
16
  });
@@ -1 +1 @@
1
- {"version":3,"names":["_CmsParametersPlugin","require","DEFAULT_LOCALE_CODE","createContextParameterPlugin","CmsParametersPlugin","context","locale","i18n","getContentLocale","code","type","exports"],"sources":["context.ts"],"sourcesContent":["import { CmsParametersPlugin } from \"~/plugins/CmsParametersPlugin\";\n\nconst DEFAULT_LOCALE_CODE = \"en-US\";\n\nexport const createContextParameterPlugin = () => {\n return new CmsParametersPlugin(async context => {\n const locale = context.i18n.getContentLocale();\n return {\n locale: locale?.code || DEFAULT_LOCALE_CODE,\n type: null\n };\n });\n};\n"],"mappings":";;;;;;AAAA,IAAAA,oBAAA,GAAAC,OAAA;AAEA,MAAMC,mBAAmB,GAAG,OAAO;AAE5B,MAAMC,4BAA4B,GAAGA,CAAA,KAAM;EAC9C,OAAO,IAAIC,wCAAmB,CAAC,MAAMC,OAAO,IAAI;IAC5C,MAAMC,MAAM,GAAGD,OAAO,CAACE,IAAI,CAACC,gBAAgB,CAAC,CAAC;IAC9C,OAAO;MACHF,MAAM,EAAE,CAAAA,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAEG,IAAI,KAAIP,mBAAmB;MAC3CQ,IAAI,EAAE;IACV,CAAC;EACL,CAAC,CAAC;AACN,CAAC;AAACC,OAAA,CAAAR,4BAAA,GAAAA,4BAAA"}
1
+ {"version":3,"names":["_CmsParametersPlugin","require","DEFAULT_LOCALE_CODE","createContextParameterPlugin","CmsParametersPlugin","context","locale","i18n","getContentLocale","code","type","exports"],"sources":["context.ts"],"sourcesContent":["import { CmsParametersPlugin } from \"~/plugins/CmsParametersPlugin\";\n\nconst DEFAULT_LOCALE_CODE = \"en-US\";\n\nexport const createContextParameterPlugin = () => {\n return new CmsParametersPlugin(async context => {\n const locale = context.i18n.getContentLocale();\n return {\n locale: locale?.code || DEFAULT_LOCALE_CODE,\n type: null\n };\n });\n};\n"],"mappings":";;;;;;AAAA,IAAAA,oBAAA,GAAAC,OAAA;AAEA,MAAMC,mBAAmB,GAAG,OAAO;AAE5B,MAAMC,4BAA4B,GAAGA,CAAA,KAAM;EAC9C,OAAO,IAAIC,wCAAmB,CAAC,MAAMC,OAAO,IAAI;IAC5C,MAAMC,MAAM,GAAGD,OAAO,CAACE,IAAI,CAACC,gBAAgB,CAAC,CAAC;IAC9C,OAAO;MACHF,MAAM,EAAEA,MAAM,EAAEG,IAAI,IAAIP,mBAAmB;MAC3CQ,IAAI,EAAE;IACV,CAAC;EACL,CAAC,CAAC;AACN,CAAC;AAACC,OAAA,CAAAR,4BAAA,GAAAA,4BAAA"}
@@ -14,11 +14,10 @@ var HeaderKeys = /*#__PURE__*/function (HeaderKeys) {
14
14
  }(HeaderKeys || {});
15
15
  const createHeaderParameterPlugin = () => {
16
16
  return new _CmsParametersPlugin.CmsParametersPlugin(async context => {
17
- var _context$request;
18
17
  /**
19
18
  * If any of the properties is not defined, just ignore this plugin
20
19
  */
21
- if (!((_context$request = context.request) !== null && _context$request !== void 0 && _context$request.headers)) {
20
+ if (!context.request?.headers) {
22
21
  return null;
23
22
  }
24
23
  const headers = context.request.headers;
@@ -1 +1 @@
1
- {"version":3,"names":["_error","_interopRequireDefault","require","_CmsParametersPlugin","HeaderKeys","createHeaderParameterPlugin","CmsParametersPlugin","context","_context$request","request","headers","type","TYPE","locale","LOCALE","WebinyError","exports"],"sources":["header.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsParametersPlugin } from \"~/plugins/CmsParametersPlugin\";\nimport { ApiEndpoint } from \"~/types\";\n\nenum HeaderKeys {\n TYPE = \"x-webiny-cms-endpoint\",\n LOCALE = \"x-webiny-cms-locale\"\n}\n\nexport const createHeaderParameterPlugin = () => {\n return new CmsParametersPlugin(async context => {\n /**\n * If any of the properties is not defined, just ignore this plugin\n */\n if (!context.request?.headers) {\n return null;\n }\n\n const headers = context.request.headers;\n\n const type = headers[HeaderKeys.TYPE];\n const locale = headers[HeaderKeys.LOCALE];\n\n if (!type && !locale) {\n return null;\n } else if (!locale || typeof locale !== \"string\") {\n throw new WebinyError(\n `There is a \"${HeaderKeys.TYPE}\" header but no \"${HeaderKeys.LOCALE}\".`,\n \"MALFORMED_HEADERS_ERROR\",\n {\n headers\n }\n );\n } else if (!type || typeof type !== \"string\") {\n throw new WebinyError(\n `There is a \"${HeaderKeys.LOCALE}\" header but no \"${HeaderKeys.TYPE}\".`,\n \"MALFORMED_HEADERS_ERROR\",\n {\n headers\n }\n );\n }\n\n return {\n type: type as ApiEndpoint,\n locale\n };\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,oBAAA,GAAAD,OAAA;AAAoE,IAG/DE,UAAU,0BAAVA,UAAU;EAAVA,UAAU;EAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA,EAAVA,UAAU;AAKR,MAAMC,2BAA2B,GAAGA,CAAA,KAAM;EAC7C,OAAO,IAAIC,wCAAmB,CAAC,MAAMC,OAAO,IAAI;IAAA,IAAAC,gBAAA;IAC5C;AACR;AACA;IACQ,IAAI,GAAAA,gBAAA,GAACD,OAAO,CAACE,OAAO,cAAAD,gBAAA,eAAfA,gBAAA,CAAiBE,OAAO,GAAE;MAC3B,OAAO,IAAI;IACf;IAEA,MAAMA,OAAO,GAAGH,OAAO,CAACE,OAAO,CAACC,OAAO;IAEvC,MAAMC,IAAI,GAAGD,OAAO,CAACN,UAAU,CAACQ,IAAI,CAAC;IACrC,MAAMC,MAAM,GAAGH,OAAO,CAACN,UAAU,CAACU,MAAM,CAAC;IAEzC,IAAI,CAACH,IAAI,IAAI,CAACE,MAAM,EAAE;MAClB,OAAO,IAAI;IACf,CAAC,MAAM,IAAI,CAACA,MAAM,IAAI,OAAOA,MAAM,KAAK,QAAQ,EAAE;MAC9C,MAAM,IAAIE,cAAW,CAChB,eAAcX,UAAU,CAACQ,IAAK,oBAAmBR,UAAU,CAACU,MAAO,IAAG,EACvE,yBAAyB,EACzB;QACIJ;MACJ,CACJ,CAAC;IACL,CAAC,MAAM,IAAI,CAACC,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;MAC1C,MAAM,IAAII,cAAW,CAChB,eAAcX,UAAU,CAACU,MAAO,oBAAmBV,UAAU,CAACQ,IAAK,IAAG,EACvE,yBAAyB,EACzB;QACIF;MACJ,CACJ,CAAC;IACL;IAEA,OAAO;MACHC,IAAI,EAAEA,IAAmB;MACzBE;IACJ,CAAC;EACL,CAAC,CAAC;AACN,CAAC;AAACG,OAAA,CAAAX,2BAAA,GAAAA,2BAAA"}
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_CmsParametersPlugin","HeaderKeys","createHeaderParameterPlugin","CmsParametersPlugin","context","request","headers","type","TYPE","locale","LOCALE","WebinyError","exports"],"sources":["header.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsParametersPlugin } from \"~/plugins/CmsParametersPlugin\";\nimport { ApiEndpoint } from \"~/types\";\n\nenum HeaderKeys {\n TYPE = \"x-webiny-cms-endpoint\",\n LOCALE = \"x-webiny-cms-locale\"\n}\n\nexport const createHeaderParameterPlugin = () => {\n return new CmsParametersPlugin(async context => {\n /**\n * If any of the properties is not defined, just ignore this plugin\n */\n if (!context.request?.headers) {\n return null;\n }\n\n const headers = context.request.headers;\n\n const type = headers[HeaderKeys.TYPE];\n const locale = headers[HeaderKeys.LOCALE];\n\n if (!type && !locale) {\n return null;\n } else if (!locale || typeof locale !== \"string\") {\n throw new WebinyError(\n `There is a \"${HeaderKeys.TYPE}\" header but no \"${HeaderKeys.LOCALE}\".`,\n \"MALFORMED_HEADERS_ERROR\",\n {\n headers\n }\n );\n } else if (!type || typeof type !== \"string\") {\n throw new WebinyError(\n `There is a \"${HeaderKeys.LOCALE}\" header but no \"${HeaderKeys.TYPE}\".`,\n \"MALFORMED_HEADERS_ERROR\",\n {\n headers\n }\n );\n }\n\n return {\n type: type as ApiEndpoint,\n locale\n };\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,oBAAA,GAAAD,OAAA;AAAoE,IAG/DE,UAAU,0BAAVA,UAAU;EAAVA,UAAU;EAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA,EAAVA,UAAU;AAKR,MAAMC,2BAA2B,GAAGA,CAAA,KAAM;EAC7C,OAAO,IAAIC,wCAAmB,CAAC,MAAMC,OAAO,IAAI;IAC5C;AACR;AACA;IACQ,IAAI,CAACA,OAAO,CAACC,OAAO,EAAEC,OAAO,EAAE;MAC3B,OAAO,IAAI;IACf;IAEA,MAAMA,OAAO,GAAGF,OAAO,CAACC,OAAO,CAACC,OAAO;IAEvC,MAAMC,IAAI,GAAGD,OAAO,CAACL,UAAU,CAACO,IAAI,CAAC;IACrC,MAAMC,MAAM,GAAGH,OAAO,CAACL,UAAU,CAACS,MAAM,CAAC;IAEzC,IAAI,CAACH,IAAI,IAAI,CAACE,MAAM,EAAE;MAClB,OAAO,IAAI;IACf,CAAC,MAAM,IAAI,CAACA,MAAM,IAAI,OAAOA,MAAM,KAAK,QAAQ,EAAE;MAC9C,MAAM,IAAIE,cAAW,CAChB,eAAcV,UAAU,CAACO,IAAK,oBAAmBP,UAAU,CAACS,MAAO,IAAG,EACvE,yBAAyB,EACzB;QACIJ;MACJ,CACJ,CAAC;IACL,CAAC,MAAM,IAAI,CAACC,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;MAC1C,MAAM,IAAII,cAAW,CAChB,eAAcV,UAAU,CAACS,MAAO,oBAAmBT,UAAU,CAACO,IAAK,IAAG,EACvE,yBAAyB,EACzB;QACIF;MACJ,CACJ,CAAC;IACL;IAEA,OAAO;MACHC,IAAI,EAAEA,IAAmB;MACzBE;IACJ,CAAC;EACL,CAAC,CAAC;AACN,CAAC;AAACG,OAAA,CAAAV,2BAAA,GAAAA,2BAAA"}
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.createManualPlugin = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
8
  var _error = _interopRequireDefault(require("@webiny/error"));
10
9
  var _CmsParametersPlugin = require("../plugins/CmsParametersPlugin");
11
10
  /**
@@ -24,9 +23,13 @@ const createManualPlugin = params => {
24
23
  if (!type && !locale) {
25
24
  return null;
26
25
  } else if (!type) {
27
- throw new _error.default(`There is defined "locale" CMS parameter but no "endpointType".`, "MALFORMED_ENDPOINT_TYPE", (0, _objectSpread2.default)({}, params));
26
+ throw new _error.default(`There is defined "locale" CMS parameter but no "endpointType".`, "MALFORMED_ENDPOINT_TYPE", {
27
+ ...params
28
+ });
28
29
  } else if (!locale) {
29
- throw new _error.default(`There is defined "endpointType" CMS parameter but no "locale".`, "MALFORMED_LOCALE_TYPE", (0, _objectSpread2.default)({}, params));
30
+ throw new _error.default(`There is defined "endpointType" CMS parameter but no "locale".`, "MALFORMED_LOCALE_TYPE", {
31
+ ...params
32
+ });
30
33
  }
31
34
  return {
32
35
  type,
@@ -1 +1 @@
1
- {"version":3,"names":["_error","_interopRequireDefault","require","_CmsParametersPlugin","createManualPlugin","params","CmsParametersPlugin","endpointType","type","locale","WebinyError","_objectSpread2","default","exports"],"sources":["manual.ts"],"sourcesContent":["/**\n * This would be used for custom Lambdas when there is no path or header information about the endpoint type and locale.\n */\nimport WebinyError from \"@webiny/error\";\nimport {\n CmsParametersPlugin,\n CmsParametersPluginResponseLocale,\n CmsParametersPluginResponseType\n} from \"~/plugins/CmsParametersPlugin\";\n\nexport interface ManualPluginParams {\n endpointType?: CmsParametersPluginResponseType;\n locale?: CmsParametersPluginResponseLocale;\n}\n\nexport const createManualPlugin = (params: ManualPluginParams): CmsParametersPlugin => {\n return new CmsParametersPlugin(async () => {\n const { endpointType: type, locale } = params;\n /**\n * if both of parameters are not existing, just skip this plugin.\n */\n if (!type && !locale) {\n return null;\n } else if (!type) {\n throw new WebinyError(\n `There is defined \"locale\" CMS parameter but no \"endpointType\".`,\n \"MALFORMED_ENDPOINT_TYPE\",\n {\n ...params\n }\n );\n } else if (!locale) {\n throw new WebinyError(\n `There is defined \"endpointType\" CMS parameter but no \"locale\".`,\n \"MALFORMED_LOCALE_TYPE\",\n {\n ...params\n }\n );\n }\n\n return {\n type,\n locale\n };\n });\n};\n"],"mappings":";;;;;;;;AAGA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,oBAAA,GAAAD,OAAA;AAJA;AACA;AACA;;AAaO,MAAME,kBAAkB,GAAIC,MAA0B,IAA0B;EACnF,OAAO,IAAIC,wCAAmB,CAAC,YAAY;IACvC,MAAM;MAAEC,YAAY,EAAEC,IAAI;MAAEC;IAAO,CAAC,GAAGJ,MAAM;IAC7C;AACR;AACA;IACQ,IAAI,CAACG,IAAI,IAAI,CAACC,MAAM,EAAE;MAClB,OAAO,IAAI;IACf,CAAC,MAAM,IAAI,CAACD,IAAI,EAAE;MACd,MAAM,IAAIE,cAAW,CAChB,gEAA+D,EAChE,yBAAyB,MAAAC,cAAA,CAAAC,OAAA,MAElBP,MAAM,CAEjB,CAAC;IACL,CAAC,MAAM,IAAI,CAACI,MAAM,EAAE;MAChB,MAAM,IAAIC,cAAW,CAChB,gEAA+D,EAChE,uBAAuB,MAAAC,cAAA,CAAAC,OAAA,MAEhBP,MAAM,CAEjB,CAAC;IACL;IAEA,OAAO;MACHG,IAAI;MACJC;IACJ,CAAC;EACL,CAAC,CAAC;AACN,CAAC;AAACI,OAAA,CAAAT,kBAAA,GAAAA,kBAAA"}
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_CmsParametersPlugin","createManualPlugin","params","CmsParametersPlugin","endpointType","type","locale","WebinyError","exports"],"sources":["manual.ts"],"sourcesContent":["/**\n * This would be used for custom Lambdas when there is no path or header information about the endpoint type and locale.\n */\nimport WebinyError from \"@webiny/error\";\nimport {\n CmsParametersPlugin,\n CmsParametersPluginResponseLocale,\n CmsParametersPluginResponseType\n} from \"~/plugins/CmsParametersPlugin\";\n\nexport interface ManualPluginParams {\n endpointType?: CmsParametersPluginResponseType;\n locale?: CmsParametersPluginResponseLocale;\n}\n\nexport const createManualPlugin = (params: ManualPluginParams): CmsParametersPlugin => {\n return new CmsParametersPlugin(async () => {\n const { endpointType: type, locale } = params;\n /**\n * if both of parameters are not existing, just skip this plugin.\n */\n if (!type && !locale) {\n return null;\n } else if (!type) {\n throw new WebinyError(\n `There is defined \"locale\" CMS parameter but no \"endpointType\".`,\n \"MALFORMED_ENDPOINT_TYPE\",\n {\n ...params\n }\n );\n } else if (!locale) {\n throw new WebinyError(\n `There is defined \"endpointType\" CMS parameter but no \"locale\".`,\n \"MALFORMED_LOCALE_TYPE\",\n {\n ...params\n }\n );\n }\n\n return {\n type,\n locale\n };\n });\n};\n"],"mappings":";;;;;;;AAGA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,oBAAA,GAAAD,OAAA;AAJA;AACA;AACA;;AAaO,MAAME,kBAAkB,GAAIC,MAA0B,IAA0B;EACnF,OAAO,IAAIC,wCAAmB,CAAC,YAAY;IACvC,MAAM;MAAEC,YAAY,EAAEC,IAAI;MAAEC;IAAO,CAAC,GAAGJ,MAAM;IAC7C;AACR;AACA;IACQ,IAAI,CAACG,IAAI,IAAI,CAACC,MAAM,EAAE;MAClB,OAAO,IAAI;IACf,CAAC,MAAM,IAAI,CAACD,IAAI,EAAE;MACd,MAAM,IAAIE,cAAW,CAChB,gEAA+D,EAChE,yBAAyB,EACzB;QACI,GAAGL;MACP,CACJ,CAAC;IACL,CAAC,MAAM,IAAI,CAACI,MAAM,EAAE;MAChB,MAAM,IAAIC,cAAW,CAChB,gEAA+D,EAChE,uBAAuB,EACvB;QACI,GAAGL;MACP,CACJ,CAAC;IACL;IAEA,OAAO;MACHG,IAAI;MACJC;IACJ,CAAC;EACL,CAAC,CAAC;AACN,CAAC;AAACE,OAAA,CAAAP,kBAAA,GAAAA,kBAAA"}
@@ -10,11 +10,10 @@ var _CmsParametersPlugin = require("../plugins/CmsParametersPlugin");
10
10
  const allowedEndpoints = ["manage", "read", "preview"];
11
11
  const createPathParameterPlugin = () => {
12
12
  return new _CmsParametersPlugin.CmsParametersPlugin(async context => {
13
- var _context$request;
14
13
  /**
15
14
  * If any of the properties is not defined, just ignore this plugin
16
15
  */
17
- if (!((_context$request = context.request) !== null && _context$request !== void 0 && _context$request.params)) {
16
+ if (!context.request?.params) {
18
17
  return null;
19
18
  }
20
19
  const {
@@ -1 +1 @@
1
- {"version":3,"names":["_error","_interopRequireDefault","require","_CmsParametersPlugin","allowedEndpoints","createPathParameterPlugin","CmsParametersPlugin","context","_context$request","request","params","type","locale","WebinyError","includes","exports"],"sources":["path.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsParametersPlugin } from \"~/plugins/CmsParametersPlugin\";\nimport { ApiEndpoint } from \"~/types\";\n\nconst allowedEndpoints: ApiEndpoint[] = [\"manage\", \"read\", \"preview\"];\n\nexport const createPathParameterPlugin = () => {\n return new CmsParametersPlugin(async context => {\n /**\n * If any of the properties is not defined, just ignore this plugin\n */\n if (!context.request?.params) {\n return null;\n }\n\n const { type, locale } = context.request.params as Record<string, string | null>;\n if (!type && !locale) {\n return null;\n }\n\n if (!type) {\n throw new WebinyError(`Missing request parameter \"type\".`);\n } else if (!locale) {\n throw new WebinyError(`Missing request parameter \"locale\".`);\n } else if (allowedEndpoints.includes(type as ApiEndpoint) === false) {\n throw new WebinyError(`Endpoint \"${type}\" not allowed!`);\n }\n\n return {\n type: type as ApiEndpoint,\n locale\n };\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,oBAAA,GAAAD,OAAA;AAGA,MAAME,gBAA+B,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC;AAE9D,MAAMC,yBAAyB,GAAGA,CAAA,KAAM;EAC3C,OAAO,IAAIC,wCAAmB,CAAC,MAAMC,OAAO,IAAI;IAAA,IAAAC,gBAAA;IAC5C;AACR;AACA;IACQ,IAAI,GAAAA,gBAAA,GAACD,OAAO,CAACE,OAAO,cAAAD,gBAAA,eAAfA,gBAAA,CAAiBE,MAAM,GAAE;MAC1B,OAAO,IAAI;IACf;IAEA,MAAM;MAAEC,IAAI;MAAEC;IAAO,CAAC,GAAGL,OAAO,CAACE,OAAO,CAACC,MAAuC;IAChF,IAAI,CAACC,IAAI,IAAI,CAACC,MAAM,EAAE;MAClB,OAAO,IAAI;IACf;IAEA,IAAI,CAACD,IAAI,EAAE;MACP,MAAM,IAAIE,cAAW,CAAE,mCAAkC,CAAC;IAC9D,CAAC,MAAM,IAAI,CAACD,MAAM,EAAE;MAChB,MAAM,IAAIC,cAAW,CAAE,qCAAoC,CAAC;IAChE,CAAC,MAAM,IAAIT,gBAAgB,CAACU,QAAQ,CAACH,IAAmB,CAAC,KAAK,KAAK,EAAE;MACjE,MAAM,IAAIE,cAAW,CAAE,aAAYF,IAAK,gBAAe,CAAC;IAC5D;IAEA,OAAO;MACHA,IAAI,EAAEA,IAAmB;MACzBC;IACJ,CAAC;EACL,CAAC,CAAC;AACN,CAAC;AAACG,OAAA,CAAAV,yBAAA,GAAAA,yBAAA"}
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_CmsParametersPlugin","allowedEndpoints","createPathParameterPlugin","CmsParametersPlugin","context","request","params","type","locale","WebinyError","includes","exports"],"sources":["path.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsParametersPlugin } from \"~/plugins/CmsParametersPlugin\";\nimport { ApiEndpoint } from \"~/types\";\n\nconst allowedEndpoints: ApiEndpoint[] = [\"manage\", \"read\", \"preview\"];\n\nexport const createPathParameterPlugin = () => {\n return new CmsParametersPlugin(async context => {\n /**\n * If any of the properties is not defined, just ignore this plugin\n */\n if (!context.request?.params) {\n return null;\n }\n\n const { type, locale } = context.request.params as Record<string, string | null>;\n if (!type && !locale) {\n return null;\n }\n\n if (!type) {\n throw new WebinyError(`Missing request parameter \"type\".`);\n } else if (!locale) {\n throw new WebinyError(`Missing request parameter \"locale\".`);\n } else if (allowedEndpoints.includes(type as ApiEndpoint) === false) {\n throw new WebinyError(`Endpoint \"${type}\" not allowed!`);\n }\n\n return {\n type: type as ApiEndpoint,\n locale\n };\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,oBAAA,GAAAD,OAAA;AAGA,MAAME,gBAA+B,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC;AAE9D,MAAMC,yBAAyB,GAAGA,CAAA,KAAM;EAC3C,OAAO,IAAIC,wCAAmB,CAAC,MAAMC,OAAO,IAAI;IAC5C;AACR;AACA;IACQ,IAAI,CAACA,OAAO,CAACC,OAAO,EAAEC,MAAM,EAAE;MAC1B,OAAO,IAAI;IACf;IAEA,MAAM;MAAEC,IAAI;MAAEC;IAAO,CAAC,GAAGJ,OAAO,CAACC,OAAO,CAACC,MAAuC;IAChF,IAAI,CAACC,IAAI,IAAI,CAACC,MAAM,EAAE;MAClB,OAAO,IAAI;IACf;IAEA,IAAI,CAACD,IAAI,EAAE;MACP,MAAM,IAAIE,cAAW,CAAE,mCAAkC,CAAC;IAC9D,CAAC,MAAM,IAAI,CAACD,MAAM,EAAE;MAChB,MAAM,IAAIC,cAAW,CAAE,qCAAoC,CAAC;IAChE,CAAC,MAAM,IAAIR,gBAAgB,CAACS,QAAQ,CAACH,IAAmB,CAAC,KAAK,KAAK,EAAE;MACjE,MAAM,IAAIE,cAAW,CAAE,aAAYF,IAAK,gBAAe,CAAC;IAC5D;IAEA,OAAO;MACHA,IAAI,EAAEA,IAAmB;MACzBC;IACJ,CAAC;EACL,CAAC,CAAC;AACN,CAAC;AAACG,OAAA,CAAAT,yBAAA,GAAAA,yBAAA"}
@@ -1,14 +1,13 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.CmsGraphQLSchemaPlugin = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
7
  var _handlerGraphql = require("@webiny/handler-graphql");
10
- class CmsGraphQLSchemaPlugin extends _handlerGraphql.GraphQLSchemaPlugin {}
8
+ class CmsGraphQLSchemaPlugin extends _handlerGraphql.GraphQLSchemaPlugin {
9
+ static type = "cms.graphql.schema";
10
+ }
11
11
  exports.CmsGraphQLSchemaPlugin = CmsGraphQLSchemaPlugin;
12
- (0, _defineProperty2.default)(CmsGraphQLSchemaPlugin, "type", "cms.graphql.schema");
13
12
 
14
13
  //# sourceMappingURL=CmsGraphQLSchemaPlugin.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_handlerGraphql","require","CmsGraphQLSchemaPlugin","GraphQLSchemaPlugin","exports","_defineProperty2","default"],"sources":["CmsGraphQLSchemaPlugin.ts"],"sourcesContent":["import { GraphQLSchemaPlugin } from \"@webiny/handler-graphql\";\nimport { CmsContext } from \"~/types\";\n\nexport class CmsGraphQLSchemaPlugin<T = CmsContext> extends GraphQLSchemaPlugin<T> {\n public static override type = \"cms.graphql.schema\";\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAGO,MAAMC,sBAAsB,SAAyBC,mCAAmB,CAAI;AAElFC,OAAA,CAAAF,sBAAA,GAAAA,sBAAA;AAAA,IAAAG,gBAAA,CAAAC,OAAA,EAFYJ,sBAAsB,UACD,oBAAoB"}
1
+ {"version":3,"names":["_handlerGraphql","require","CmsGraphQLSchemaPlugin","GraphQLSchemaPlugin","type","exports"],"sources":["CmsGraphQLSchemaPlugin.ts"],"sourcesContent":["import { GraphQLSchemaPlugin } from \"@webiny/handler-graphql\";\nimport { CmsContext } from \"~/types\";\n\nexport class CmsGraphQLSchemaPlugin<T = CmsContext> extends GraphQLSchemaPlugin<T> {\n public static override type = \"cms.graphql.schema\";\n}\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAGO,MAAMC,sBAAsB,SAAyBC,mCAAmB,CAAI;EAC/E,OAAuBC,IAAI,GAAG,oBAAoB;AACtD;AAACC,OAAA,CAAAH,sBAAA,GAAAA,sBAAA"}
@@ -1,16 +1,14 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.createCmsGraphQLSchemaSorterPlugin = exports.CmsGraphQLSchemaSorterPlugin = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
7
  var _plugins = require("@webiny/plugins");
10
8
  class CmsGraphQLSchemaSorterPlugin extends _plugins.Plugin {
9
+ static type = "cms.graphql.schema.sorter";
11
10
  constructor(cb) {
12
11
  super();
13
- (0, _defineProperty2.default)(this, "cb", void 0);
14
12
  this.cb = cb;
15
13
  }
16
14
  /**
@@ -21,7 +19,6 @@ class CmsGraphQLSchemaSorterPlugin extends _plugins.Plugin {
21
19
  }
22
20
  }
23
21
  exports.CmsGraphQLSchemaSorterPlugin = CmsGraphQLSchemaSorterPlugin;
24
- (0, _defineProperty2.default)(CmsGraphQLSchemaSorterPlugin, "type", "cms.graphql.schema.sorter");
25
22
  const createCmsGraphQLSchemaSorterPlugin = cb => {
26
23
  return new CmsGraphQLSchemaSorterPlugin(cb);
27
24
  };
@@ -1 +1 @@
1
- {"version":3,"names":["_plugins","require","CmsGraphQLSchemaSorterPlugin","Plugin","constructor","cb","_defineProperty2","default","createSorter","params","exports","createCmsGraphQLSchemaSorterPlugin"],"sources":["CmsGraphQLSchemaSorterPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { CmsModel } from \"~/types\";\n\ninterface CmsGraphQLSchemaSorterPluginCallableParams {\n model: CmsModel;\n sorters: string[];\n}\ninterface CmsGraphQLSchemaSorterPluginCallable {\n (params: CmsGraphQLSchemaSorterPluginCallableParams): string[];\n}\nexport class CmsGraphQLSchemaSorterPlugin extends Plugin {\n public static override readonly type: string = \"cms.graphql.schema.sorter\";\n\n private readonly cb: CmsGraphQLSchemaSorterPluginCallable;\n public constructor(cb: CmsGraphQLSchemaSorterPluginCallable) {\n super();\n\n this.cb = cb;\n }\n /**\n * Method must return new sorting array. Or existing one if no changes are made.\n */\n public createSorter(params: CmsGraphQLSchemaSorterPluginCallableParams): string[] {\n return this.cb(params);\n }\n}\n\nexport const createCmsGraphQLSchemaSorterPlugin = (\n cb: CmsGraphQLSchemaSorterPluginCallable\n): CmsGraphQLSchemaSorterPlugin => {\n return new CmsGraphQLSchemaSorterPlugin(cb);\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAUO,MAAMC,4BAA4B,SAASC,eAAM,CAAC;EAI9CC,WAAWA,CAACC,EAAwC,EAAE;IACzD,KAAK,CAAC,CAAC;IAAC,IAAAC,gBAAA,CAAAC,OAAA;IAER,IAAI,CAACF,EAAE,GAAGA,EAAE;EAChB;EACA;AACJ;AACA;EACWG,YAAYA,CAACC,MAAkD,EAAY;IAC9E,OAAO,IAAI,CAACJ,EAAE,CAACI,MAAM,CAAC;EAC1B;AACJ;AAACC,OAAA,CAAAR,4BAAA,GAAAA,4BAAA;AAAA,IAAAI,gBAAA,CAAAC,OAAA,EAfYL,4BAA4B,UACU,2BAA2B;AAgBvE,MAAMS,kCAAkC,GAC3CN,EAAwC,IACT;EAC/B,OAAO,IAAIH,4BAA4B,CAACG,EAAE,CAAC;AAC/C,CAAC;AAACK,OAAA,CAAAC,kCAAA,GAAAA,kCAAA"}
1
+ {"version":3,"names":["_plugins","require","CmsGraphQLSchemaSorterPlugin","Plugin","type","constructor","cb","createSorter","params","exports","createCmsGraphQLSchemaSorterPlugin"],"sources":["CmsGraphQLSchemaSorterPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { CmsModel } from \"~/types\";\n\ninterface CmsGraphQLSchemaSorterPluginCallableParams {\n model: CmsModel;\n sorters: string[];\n}\ninterface CmsGraphQLSchemaSorterPluginCallable {\n (params: CmsGraphQLSchemaSorterPluginCallableParams): string[];\n}\nexport class CmsGraphQLSchemaSorterPlugin extends Plugin {\n public static override readonly type: string = \"cms.graphql.schema.sorter\";\n\n private readonly cb: CmsGraphQLSchemaSorterPluginCallable;\n public constructor(cb: CmsGraphQLSchemaSorterPluginCallable) {\n super();\n\n this.cb = cb;\n }\n /**\n * Method must return new sorting array. Or existing one if no changes are made.\n */\n public createSorter(params: CmsGraphQLSchemaSorterPluginCallableParams): string[] {\n return this.cb(params);\n }\n}\n\nexport const createCmsGraphQLSchemaSorterPlugin = (\n cb: CmsGraphQLSchemaSorterPluginCallable\n): CmsGraphQLSchemaSorterPlugin => {\n return new CmsGraphQLSchemaSorterPlugin(cb);\n};\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAUO,MAAMC,4BAA4B,SAASC,eAAM,CAAC;EACrD,OAAgCC,IAAI,GAAW,2BAA2B;EAGnEC,WAAWA,CAACC,EAAwC,EAAE;IACzD,KAAK,CAAC,CAAC;IAEP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;EACA;AACJ;AACA;EACWC,YAAYA,CAACC,MAAkD,EAAY;IAC9E,OAAO,IAAI,CAACF,EAAE,CAACE,MAAM,CAAC;EAC1B;AACJ;AAACC,OAAA,CAAAP,4BAAA,GAAAA,4BAAA;AAEM,MAAMQ,kCAAkC,GAC3CJ,EAAwC,IACT;EAC/B,OAAO,IAAIJ,4BAA4B,CAACI,EAAE,CAAC;AAC/C,CAAC;AAACG,OAAA,CAAAC,kCAAA,GAAAA,kCAAA"}
@@ -1,24 +1,21 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.createCmsGroup = exports.CmsGroupPlugin = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
7
  var _plugins = require("@webiny/plugins");
11
8
  class CmsGroupPlugin extends _plugins.Plugin {
9
+ static type = "cms-content-model-group";
12
10
  constructor(contentModelGroup) {
13
11
  super();
14
- (0, _defineProperty2.default)(this, "contentModelGroup", void 0);
15
- this.contentModelGroup = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, contentModelGroup), {}, {
12
+ this.contentModelGroup = {
13
+ ...contentModelGroup,
16
14
  isPlugin: true
17
- });
15
+ };
18
16
  }
19
17
  }
20
18
  exports.CmsGroupPlugin = CmsGroupPlugin;
21
- (0, _defineProperty2.default)(CmsGroupPlugin, "type", "cms-content-model-group");
22
19
  const createCmsGroup = group => {
23
20
  return new CmsGroupPlugin(group);
24
21
  };
@@ -1 +1 @@
1
- {"version":3,"names":["_plugins","require","CmsGroupPlugin","Plugin","constructor","contentModelGroup","_defineProperty2","default","_objectSpread2","isPlugin","exports","createCmsGroup","group"],"sources":["CmsGroupPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { CmsGroup as BaseCmsGroup } from \"~/types\";\n\nexport interface CmsGroupInput\n extends Omit<BaseCmsGroup, \"locale\" | \"tenant\" | \"webinyVersion\" | \"isPlugin\"> {\n tenant?: string;\n locale?: string;\n}\n\nexport interface CmsGroup extends Omit<BaseCmsGroup, \"locale\" | \"tenant\" | \"webinyVersion\"> {\n tenant?: string;\n locale?: string;\n}\n\nexport class CmsGroupPlugin extends Plugin {\n public static override readonly type: string = \"cms-content-model-group\";\n public readonly contentModelGroup: CmsGroup;\n\n constructor(contentModelGroup: CmsGroupInput) {\n super();\n this.contentModelGroup = {\n ...contentModelGroup,\n isPlugin: true\n };\n }\n}\n\nexport const createCmsGroup = (group: CmsGroup): CmsGroupPlugin => {\n return new CmsGroupPlugin(group);\n};\n"],"mappings":";;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAcO,MAAMC,cAAc,SAASC,eAAM,CAAC;EAIvCC,WAAWA,CAACC,iBAAgC,EAAE;IAC1C,KAAK,CAAC,CAAC;IAAC,IAAAC,gBAAA,CAAAC,OAAA;IACR,IAAI,CAACF,iBAAiB,OAAAG,cAAA,CAAAD,OAAA,MAAAC,cAAA,CAAAD,OAAA,MACfF,iBAAiB;MACpBI,QAAQ,EAAE;IAAI,EACjB;EACL;AACJ;AAACC,OAAA,CAAAR,cAAA,GAAAA,cAAA;AAAA,IAAAI,gBAAA,CAAAC,OAAA,EAXYL,cAAc,UACwB,yBAAyB;AAYrE,MAAMS,cAAc,GAAIC,KAAe,IAAqB;EAC/D,OAAO,IAAIV,cAAc,CAACU,KAAK,CAAC;AACpC,CAAC;AAACF,OAAA,CAAAC,cAAA,GAAAA,cAAA"}
1
+ {"version":3,"names":["_plugins","require","CmsGroupPlugin","Plugin","type","constructor","contentModelGroup","isPlugin","exports","createCmsGroup","group"],"sources":["CmsGroupPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { CmsGroup as BaseCmsGroup } from \"~/types\";\n\nexport interface CmsGroupInput\n extends Omit<BaseCmsGroup, \"locale\" | \"tenant\" | \"webinyVersion\" | \"isPlugin\"> {\n tenant?: string;\n locale?: string;\n}\n\nexport interface CmsGroup extends Omit<BaseCmsGroup, \"locale\" | \"tenant\" | \"webinyVersion\"> {\n tenant?: string;\n locale?: string;\n}\n\nexport class CmsGroupPlugin extends Plugin {\n public static override readonly type: string = \"cms-content-model-group\";\n public readonly contentModelGroup: CmsGroup;\n\n constructor(contentModelGroup: CmsGroupInput) {\n super();\n this.contentModelGroup = {\n ...contentModelGroup,\n isPlugin: true\n };\n }\n}\n\nexport const createCmsGroup = (group: CmsGroup): CmsGroupPlugin => {\n return new CmsGroupPlugin(group);\n};\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAcO,MAAMC,cAAc,SAASC,eAAM,CAAC;EACvC,OAAgCC,IAAI,GAAW,yBAAyB;EAGxEC,WAAWA,CAACC,iBAAgC,EAAE;IAC1C,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,iBAAiB,GAAG;MACrB,GAAGA,iBAAiB;MACpBC,QAAQ,EAAE;IACd,CAAC;EACL;AACJ;AAACC,OAAA,CAAAN,cAAA,GAAAA,cAAA;AAEM,MAAMO,cAAc,GAAIC,KAAe,IAAqB;EAC/D,OAAO,IAAIR,cAAc,CAACQ,KAAK,CAAC;AACpC,CAAC;AAACF,OAAA,CAAAC,cAAA,GAAAA,cAAA"}
@@ -1,14 +1,13 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.CmsModelFieldConverterPlugin = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
7
  var _plugins = require("@webiny/plugins");
10
- class CmsModelFieldConverterPlugin extends _plugins.Plugin {}
8
+ class CmsModelFieldConverterPlugin extends _plugins.Plugin {
9
+ static type = "cms.field.converter";
10
+ }
11
11
  exports.CmsModelFieldConverterPlugin = CmsModelFieldConverterPlugin;
12
- (0, _defineProperty2.default)(CmsModelFieldConverterPlugin, "type", "cms.field.converter");
13
12
 
14
13
  //# sourceMappingURL=CmsModelFieldConverterPlugin.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_plugins","require","CmsModelFieldConverterPlugin","Plugin","exports","_defineProperty2","default"],"sources":["CmsModelFieldConverterPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { CmsEntryValues, CmsModelFieldWithParent } from \"~/types\";\nimport { ConverterCollection } from \"~/utils/converters/ConverterCollection\";\n\nexport interface ConvertParams<F = CmsModelFieldWithParent> {\n field: F;\n value: any;\n converterCollection: ConverterCollection;\n}\n\nexport abstract class CmsModelFieldConverterPlugin extends Plugin {\n public static override type = \"cms.field.converter\";\n\n public abstract getFieldType(): string;\n\n public abstract convertToStorage(params: ConvertParams): CmsEntryValues;\n public abstract convertFromStorage(params: ConvertParams): CmsEntryValues;\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAUO,MAAeC,4BAA4B,SAASC,eAAM,CAAC;AAOjEC,OAAA,CAAAF,4BAAA,GAAAA,4BAAA;AAAA,IAAAG,gBAAA,CAAAC,OAAA,EAPqBJ,4BAA4B,UAChB,qBAAqB"}
1
+ {"version":3,"names":["_plugins","require","CmsModelFieldConverterPlugin","Plugin","type","exports"],"sources":["CmsModelFieldConverterPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { CmsEntryValues, CmsModelFieldWithParent } from \"~/types\";\nimport { ConverterCollection } from \"~/utils/converters/ConverterCollection\";\n\nexport interface ConvertParams<F = CmsModelFieldWithParent> {\n field: F;\n value: any;\n converterCollection: ConverterCollection;\n}\n\nexport abstract class CmsModelFieldConverterPlugin extends Plugin {\n public static override type = \"cms.field.converter\";\n\n public abstract getFieldType(): string;\n\n public abstract convertToStorage(params: ConvertParams): CmsEntryValues;\n public abstract convertFromStorage(params: ConvertParams): CmsEntryValues;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAUO,MAAeC,4BAA4B,SAASC,eAAM,CAAC;EAC9D,OAAuBC,IAAI,GAAG,qBAAqB;AAMvD;AAACC,OAAA,CAAAH,4BAAA,GAAAA,4BAAA"}
@@ -20,7 +20,7 @@ interface CmsModelFieldInput extends Omit<CmsModelFieldBase, "storageId" | "sett
20
20
  */
21
21
  settings?: CmsModelFieldSettings;
22
22
  }
23
- export interface CmsApiModel extends Omit<CmsModel, "isPrivate" | "fields" | "singularApiName" | "pluralApiName" | "isPlugin"> {
23
+ export interface CmsApiModel extends Omit<CmsModelPluginModel, "isPrivate" | "fields" | "singularApiName" | "pluralApiName" | "isPlugin"> {
24
24
  isPrivate?: never;
25
25
  noValidate?: never;
26
26
  singularApiName?: string;
@@ -31,8 +31,9 @@ export interface CmsApiModelFull extends Omit<CmsApiModel, "fields" | "noValidat
31
31
  noValidate: true;
32
32
  fields: CmsModelFieldBase[];
33
33
  }
34
- interface CmsPrivateModel extends Omit<CmsModel, "isPrivate" | "singularApiName" | "pluralApiName" | "fields" | "isPlugin"> {
34
+ interface CmsPrivateModel extends Omit<CmsModelPluginModel, "isPrivate" | "singularApiName" | "pluralApiName" | "fields" | "isPlugin" | "layout" | "titleFieldId" | "description"> {
35
35
  noValidate?: never;
36
+ titleFieldId?: string;
36
37
  singularApiName?: never;
37
38
  pluralApiName?: never;
38
39
  isPrivate: true;
@@ -43,7 +44,7 @@ export interface CmsPrivateModelFull extends Omit<CmsPrivateModel, "fields" | "n
43
44
  noValidate: true;
44
45
  }
45
46
  export declare type CmsModelInput = CmsApiModel | CmsPrivateModel | CmsApiModelFull | CmsPrivateModelFull;
46
- interface CmsModel extends Omit<CmsModelBase, "locale" | "tenant" | "webinyVersion"> {
47
+ export interface CmsModelPluginModel extends Omit<CmsModelBase, "locale" | "tenant" | "webinyVersion"> {
47
48
  locale?: string;
48
49
  tenant?: string;
49
50
  }
@@ -52,7 +53,7 @@ interface CmsModelPluginOptions {
52
53
  }
53
54
  export declare class CmsModelPlugin extends Plugin {
54
55
  static readonly type: string;
55
- readonly contentModel: CmsModel;
56
+ readonly contentModel: CmsModelPluginModel;
56
57
  private readonly options;
57
58
  constructor(contentModel: CmsModelInput, options?: CmsModelPluginOptions);
58
59
  private buildModel;
@@ -60,4 +61,5 @@ export declare class CmsModelPlugin extends Plugin {
60
61
  private validateLayout;
61
62
  }
62
63
  export declare const createCmsModel: (model: CmsModelInput, options?: CmsModelPluginOptions) => CmsModelPlugin;
64
+ export declare const createPrivateModelDefinition: (input: Omit<CmsPrivateModelFull, "group" | "isPrivate" | "noValidate">) => CmsPrivateModelFull;
63
65
  export {};
@@ -4,9 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.createCmsModel = exports.CmsModelPlugin = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
7
+ exports.createPrivateModelDefinition = exports.createCmsModel = exports.CmsModelPlugin = void 0;
10
8
  var _error = _interopRequireDefault(require("@webiny/error"));
11
9
  var _camelCase = _interopRequireDefault(require("lodash/camelCase"));
12
10
  var _upperFirst = _interopRequireDefault(require("lodash/upperFirst"));
@@ -20,37 +18,52 @@ const createPluralApiName = name => {
20
18
  return (0, _pluralize.default)(createApiName(name));
21
19
  };
22
20
  class CmsModelPlugin extends _plugins.Plugin {
21
+ static type = "cms-content-model";
23
22
  constructor(contentModel, options) {
24
23
  super();
25
- (0, _defineProperty2.default)(this, "contentModel", void 0);
26
- (0, _defineProperty2.default)(this, "options", void 0);
27
24
  this.options = options || {};
28
25
  this.contentModel = this.buildModel(contentModel);
29
26
  }
30
27
  buildModel(input) {
31
- const isPrivate = input.isPrivate || false;
28
+ const isPrivate = input.isPrivate ?? false;
32
29
  const singularApiName = input.singularApiName ? createApiName(input.singularApiName) : createApiName(input.name);
33
30
  const pluralApiName = input.pluralApiName ? createApiName(input.pluralApiName) : createPluralApiName(input.name);
31
+ const modelPlugin = {
32
+ group: {
33
+ id: "",
34
+ name: ""
35
+ },
36
+ description: "",
37
+ fields: [],
38
+ isPlugin: true,
39
+ isPrivate,
40
+ layout: [],
41
+ modelId: input.modelId,
42
+ name: input.name,
43
+ pluralApiName,
44
+ singularApiName,
45
+ titleFieldId: "id"
46
+ };
34
47
  if (input.noValidate) {
35
48
  /**
36
49
  * We can safely ignore this error, because we are sure noValidate is not a model field.
37
50
  */
38
51
  // @ts-expect-error
39
52
  delete input["noValidate"];
40
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, input), {}, {
41
- isPlugin: true,
42
- isPrivate,
43
- singularApiName,
44
- pluralApiName
45
- });
53
+ return {
54
+ ...modelPlugin,
55
+ ...input,
56
+ pluralApiName,
57
+ singularApiName
58
+ };
46
59
  }
47
- const model = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, input), {}, {
48
- isPlugin: true,
49
- isPrivate,
50
- singularApiName,
60
+ const model = {
61
+ ...modelPlugin,
62
+ ...input,
51
63
  pluralApiName,
64
+ singularApiName,
52
65
  fields: this.buildFields(input, input.fields)
53
- });
66
+ };
54
67
  this.validateLayout(model);
55
68
  return model;
56
69
  }
@@ -64,7 +77,6 @@ class CmsModelPlugin extends _plugins.Plugin {
64
77
  const storageIdList = [];
65
78
  const fieldIdList = [];
66
79
  for (const input of inputFields) {
67
- var _settings;
68
80
  /**
69
81
  * Field must contain an fieldId. It is required in the graphql, but lets check it just in case
70
82
  */
@@ -96,7 +108,7 @@ class CmsModelPlugin extends _plugins.Plugin {
96
108
  /**
97
109
  * ... and fieldId must be unique.
98
110
  */
99
- if (fieldIdList.includes(fieldId) === true) {
111
+ if (fieldIdList.includes(fieldId)) {
100
112
  throw new _error.default(`Field's "fieldId" is not unique in the content model "${model.modelId}".`, "FIELD_ID_NOT_UNIQUE_ERROR", {
101
113
  model,
102
114
  field: input
@@ -119,7 +131,7 @@ class CmsModelPlugin extends _plugins.Plugin {
119
131
  /**
120
132
  * Fields storageId must be unique.
121
133
  */
122
- if (storageIdList.includes(storageId) === true) {
134
+ if (storageIdList.includes(storageId)) {
123
135
  throw new _error.default(`Field's "storageId" is not unique in the content model "${model.modelId}".`, "STORAGE_ID_ERROR", {
124
136
  model,
125
137
  field: input
@@ -129,18 +141,20 @@ class CmsModelPlugin extends _plugins.Plugin {
129
141
  /**
130
142
  * We can safely ignore error because we are going through the fields and making sure each has storageId.
131
143
  */
132
- // @ts-ignore
144
+ // @ts-expect-error
133
145
  let settings = input.settings;
134
- const childFields = ((_settings = settings) === null || _settings === void 0 ? void 0 : _settings.fields) || [];
146
+ const childFields = settings?.fields || [];
135
147
  if (input.type === "object" && childFields.length > 0) {
136
- settings = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, settings || {}), {}, {
148
+ settings = {
149
+ ...(settings || {}),
137
150
  fields: this.buildFields(model, childFields)
138
- });
151
+ };
139
152
  }
140
- const field = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, input), {}, {
153
+ const field = {
154
+ ...input,
141
155
  settings,
142
156
  storageId
143
- });
157
+ };
144
158
  /**
145
159
  * Add all relevant data to arrays.
146
160
  */
@@ -179,10 +193,21 @@ class CmsModelPlugin extends _plugins.Plugin {
179
193
  }
180
194
  }
181
195
  exports.CmsModelPlugin = CmsModelPlugin;
182
- (0, _defineProperty2.default)(CmsModelPlugin, "type", "cms-content-model");
183
196
  const createCmsModel = (model, options) => {
184
197
  return new CmsModelPlugin(model, options);
185
198
  };
186
199
  exports.createCmsModel = createCmsModel;
200
+ const createPrivateModelDefinition = input => {
201
+ return {
202
+ ...input,
203
+ isPrivate: true,
204
+ noValidate: true,
205
+ group: {
206
+ id: "private",
207
+ name: "Private Models"
208
+ }
209
+ };
210
+ };
211
+ exports.createPrivateModelDefinition = createPrivateModelDefinition;
187
212
 
188
213
  //# sourceMappingURL=CmsModelPlugin.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_error","_interopRequireDefault","require","_camelCase","_upperFirst","_pluralize","_plugins","_createFieldStorageId","createApiName","name","upperFirst","camelCase","createPluralApiName","pluralize","CmsModelPlugin","Plugin","constructor","contentModel","options","_defineProperty2","default","buildModel","input","isPrivate","singularApiName","pluralApiName","noValidate","_objectSpread2","isPlugin","model","fields","buildFields","validateLayout","inputFields","length","WebinyError","modelId","storageIdList","fieldIdList","_settings","fieldId","trim","field","lodashCamelCase","match","includes","storageId","createFieldStorageId","settings","childFields","type","push","total","row","layout","count","filter","cell","id","exports","createCmsModel"],"sources":["CmsModelPlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport lodashCamelCase from \"lodash/camelCase\";\nimport camelCase from \"lodash/camelCase\";\nimport upperFirst from \"lodash/upperFirst\";\nimport pluralize from \"pluralize\";\nimport { Plugin } from \"@webiny/plugins\";\nimport {\n CmsModel as CmsModelBase,\n CmsModelField as CmsModelFieldBase,\n CmsModelFieldSettings as BaseCmsModelFieldSettings\n} from \"~/types\";\nimport { createFieldStorageId } from \"~/crud/contentModel/createFieldStorageId\";\n\nconst createApiName = (name: string) => {\n return upperFirst(camelCase(name));\n};\n\nconst createPluralApiName = (name: string) => {\n return pluralize(createApiName(name));\n};\n\ninterface CmsModelFieldSettings extends Omit<BaseCmsModelFieldSettings, \"fields\"> {\n /**\n * Object field has child fields.\n */\n fields?: CmsModelFieldInput[];\n}\n\ninterface CmsModelFieldInput extends Omit<CmsModelFieldBase, \"storageId\" | \"settings\"> {\n /**\n * If defined, it must be camelCased string.\n * This is for backwards compatibility - before fields had storageId.\n *\n * This should only be populated in old model fields.\n * News ones must have this empty.\n */\n storageId?: string;\n /**\n * We must have a possibility to have a nested field defined without the storageId.\n */\n settings?: CmsModelFieldSettings;\n}\n\nexport interface CmsApiModel\n extends Omit<\n CmsModel,\n \"isPrivate\" | \"fields\" | \"singularApiName\" | \"pluralApiName\" | \"isPlugin\"\n > {\n isPrivate?: never;\n noValidate?: never;\n singularApiName?: string;\n pluralApiName?: string;\n fields: CmsModelFieldInput[];\n}\n\nexport interface CmsApiModelFull extends Omit<CmsApiModel, \"fields\" | \"noValidate\"> {\n noValidate: true;\n fields: CmsModelFieldBase[];\n}\n\ninterface CmsPrivateModel\n extends Omit<\n CmsModel,\n \"isPrivate\" | \"singularApiName\" | \"pluralApiName\" | \"fields\" | \"isPlugin\"\n > {\n noValidate?: never;\n singularApiName?: never;\n pluralApiName?: never;\n isPrivate: true;\n fields: CmsModelFieldInput[];\n}\n\nexport interface CmsPrivateModelFull extends Omit<CmsPrivateModel, \"fields\" | \"noValidate\"> {\n fields: CmsModelFieldBase[];\n noValidate: true;\n}\n\nexport type CmsModelInput = CmsApiModel | CmsPrivateModel | CmsApiModelFull | CmsPrivateModelFull;\n\ninterface CmsModel extends Omit<CmsModelBase, \"locale\" | \"tenant\" | \"webinyVersion\"> {\n locale?: string;\n tenant?: string;\n}\n\ninterface CmsModelPluginOptions {\n validateLayout?: boolean;\n}\n\nexport class CmsModelPlugin extends Plugin {\n public static override readonly type: string = \"cms-content-model\";\n public readonly contentModel: CmsModel;\n\n private readonly options: CmsModelPluginOptions;\n\n constructor(contentModel: CmsModelInput, options?: CmsModelPluginOptions) {\n super();\n this.options = options || {};\n this.contentModel = this.buildModel(contentModel);\n }\n\n private buildModel(input: CmsModelInput): CmsModel {\n const isPrivate = input.isPrivate || false;\n const singularApiName = input.singularApiName\n ? createApiName(input.singularApiName)\n : createApiName(input.name);\n const pluralApiName = input.pluralApiName\n ? createApiName(input.pluralApiName)\n : createPluralApiName(input.name);\n\n if (input.noValidate) {\n /**\n * We can safely ignore this error, because we are sure noValidate is not a model field.\n */\n // @ts-expect-error\n delete input[\"noValidate\"];\n return {\n ...input,\n isPlugin: true,\n isPrivate,\n singularApiName,\n pluralApiName\n };\n }\n\n const model: CmsModel = {\n ...input,\n isPlugin: true,\n isPrivate,\n singularApiName,\n pluralApiName,\n fields: this.buildFields(input, input.fields)\n };\n this.validateLayout(model);\n return model;\n }\n\n private buildFields(\n model: CmsModelInput,\n inputFields: CmsModelFieldInput[]\n ): CmsModelFieldBase[] {\n if (inputFields.length === 0) {\n throw new WebinyError(\n `Missing fields for the defined model \"${model.modelId}\".`,\n \"MISSING_FIELDS\",\n {\n model\n }\n );\n }\n const fields: CmsModelFieldBase[] = [];\n const storageIdList: string[] = [];\n const fieldIdList: string[] = [];\n for (const input of inputFields) {\n /**\n * Field must contain an fieldId. It is required in the graphql, but lets check it just in case\n */\n if (!(input.fieldId || \"\").trim()) {\n throw new WebinyError(\n `Field's \"storageId\" is not defined for the content model \"${model.modelId}\".`,\n \"FIELD_ID_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n const fieldId = lodashCamelCase(input.fieldId);\n /**\n * FieldID must be in correct pattern.\n */\n if (fieldId.match(/^[0-9]/) !== null) {\n throw new WebinyError(\n `Field's \"fieldId\" does not match correct pattern in the content model \"${model.modelId}\" - cannot start with a number.`,\n \"FIELD_FIELD_ID_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n /**\n * FieldID also must be camelCased.\n */\n if (fieldId !== input.fieldId) {\n throw new WebinyError(\n `Field's \"fieldId\" must be a camel cased string in the content model \"${model.modelId}\".`,\n \"FIELD_FIELD_ID_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n /**\n * ... and fieldId must be unique.\n */\n if (fieldIdList.includes(fieldId) === true) {\n throw new WebinyError(\n `Field's \"fieldId\" is not unique in the content model \"${model.modelId}\".`,\n \"FIELD_ID_NOT_UNIQUE_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n\n let storageId = input.storageId ? lodashCamelCase(input.storageId) : null;\n /**\n * If defined, storageId MUST be camel cased string - for backward compatibility.\n */\n if (\n storageId &&\n (storageId.match(/^([a-zA-Z-0-9]+)$/) === null || storageId !== input.storageId)\n ) {\n throw new WebinyError(\n `Field's \"storageId\" of the field with \"fieldId\" ${input.fieldId} is not camel cased string in the content model \"${model.modelId}\".`,\n \"STORAGE_ID_NOT_CAMEL_CASED_ERROR\",\n {\n model,\n storageId,\n field: input\n }\n );\n } else if (!storageId) {\n storageId = createFieldStorageId(input);\n }\n\n /**\n * Fields storageId must be unique.\n */\n if (storageIdList.includes(storageId) === true) {\n throw new WebinyError(\n `Field's \"storageId\" is not unique in the content model \"${model.modelId}\".`,\n \"STORAGE_ID_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n\n /**\n * We can safely ignore error because we are going through the fields and making sure each has storageId.\n */\n // @ts-ignore\n let settings: BaseCmsModelFieldSettings = input.settings;\n\n const childFields = settings?.fields || [];\n if (input.type === \"object\" && childFields.length > 0) {\n settings = {\n ...(settings || {}),\n fields: this.buildFields(model, childFields)\n };\n }\n\n const field: CmsModelFieldBase = {\n ...input,\n settings,\n storageId\n };\n /**\n * Add all relevant data to arrays.\n */\n fields.push(field);\n storageIdList.push(field.storageId);\n fieldIdList.push(field.fieldId);\n }\n return fields;\n }\n\n private validateLayout(model: CmsModel): void {\n /**\n * Only skip validation if option.validateLayout was set as false, explicitly.\n */\n if (this.options.validateLayout === false) {\n return;\n }\n for (const field of model.fields) {\n let total = 0;\n for (const row of model.layout) {\n const count = row.filter(cell => cell === field.id).length;\n total = total + count;\n }\n if (total === 1) {\n continue;\n } else if (total > 1) {\n throw new WebinyError(\n `Field \"${field.id}\" is in more than one layout cell.`,\n \"DUPLICATE_FIELD_IN_LAYOUT\",\n {\n model,\n field\n }\n );\n }\n throw new WebinyError(\n `Missing field \"${field.id}\" in layout.`,\n \"MISSING_FIELD_IN_LAYOUT\",\n {\n model,\n field\n }\n );\n }\n }\n}\n\nexport const createCmsModel = (\n model: CmsModelInput,\n options?: CmsModelPluginOptions\n): CmsModelPlugin => {\n return new CmsModelPlugin(model, options);\n};\n"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEA,IAAAE,WAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,UAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAMA,IAAAK,qBAAA,GAAAL,OAAA;AAEA,MAAMM,aAAa,GAAIC,IAAY,IAAK;EACpC,OAAO,IAAAC,mBAAU,EAAC,IAAAC,kBAAS,EAACF,IAAI,CAAC,CAAC;AACtC,CAAC;AAED,MAAMG,mBAAmB,GAAIH,IAAY,IAAK;EAC1C,OAAO,IAAAI,kBAAS,EAACL,aAAa,CAACC,IAAI,CAAC,CAAC;AACzC,CAAC;AAqEM,MAAMK,cAAc,SAASC,eAAM,CAAC;EAMvCC,WAAWA,CAACC,YAA2B,EAAEC,OAA+B,EAAE;IACtE,KAAK,CAAC,CAAC;IAAC,IAAAC,gBAAA,CAAAC,OAAA;IAAA,IAAAD,gBAAA,CAAAC,OAAA;IACR,IAAI,CAACF,OAAO,GAAGA,OAAO,IAAI,CAAC,CAAC;IAC5B,IAAI,CAACD,YAAY,GAAG,IAAI,CAACI,UAAU,CAACJ,YAAY,CAAC;EACrD;EAEQI,UAAUA,CAACC,KAAoB,EAAY;IAC/C,MAAMC,SAAS,GAAGD,KAAK,CAACC,SAAS,IAAI,KAAK;IAC1C,MAAMC,eAAe,GAAGF,KAAK,CAACE,eAAe,GACvChB,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ACR;AACA;IACQ,IAAI,IAAI,CAACX,OAAO,CAACc,cAAc,KAAK,KAAK,EAAE;MACvC;IACJ;IACA,KAAK,MAAMU,KAAK,IAAIb,KAAK,CAACC,MAAM,EAAE;MAC9B,IAAIsB,KAAK,GAAG,CAAC;MACb,KAAK,MAAMC,GAAG,IAAIxB,KAAK,CAACyB,MAAM,EAAE;QAC5B,MAAMC,KAAK,GAAGF,GAAG,CAACG,MAAM,CAACC,IAAI,IAAIA,IAAI,KAAKf,KAAK,CAACgB,EAAE,CAAC,CAACxB,MAAM;QAC1DkB,KAAK,GAAGA,KAAK,GAAGG,KAAK;MACzB;MACA,IAAIH,KAAK,KAAK,CAAC,EAAE;QACb;MACJ,CAAC,MAAM,IAAIA,KAAK,GAAG,CAAC,EAAE;QAClB,MAAM,IAAIjB,cAAW,CAChB,UAASO,KAAK,CAACgB,EAAG,oCAAmC,EACtD,2BAA2B,EAC3B;UACI7B,KAAK;UACLa;QACJ,CACJ,CAAC;MACL;MACA,MAAM,IAAIP,cAAW,CAChB,kBAAiBO,KAAK,CAACgB,EAAG,cAAa,EACxC,yBAAyB,EACzB;QACI7B,KAAK;QACLa;MACJ,CACJ,CAAC;IACL;EACJ;AACJ;AAACiB,OAAA,CAAA7C,cAAA,GAAAA,cAAA;AAAA,IAAAK,gBAAA,CAAAC,OAAA,EA1NYN,cAAc,UACwB,mBAAmB;AA2N/D,MAAM8C,cAAc,GAAGA,CAC1B/B,KAAoB,EACpBX,OAA+B,KACd;EACjB,OAAO,IAAIJ,cAAc,CAACe,KAAK,EAAEX,OAAO,CAAC;AAC7C,CAAC;AAACyC,OAAA,CAAAC,cAAA,GAAAA,cAAA"}
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_camelCase","_upperFirst","_pluralize","_plugins","_createFieldStorageId","createApiName","name","upperFirst","camelCase","createPluralApiName","pluralize","CmsModelPlugin","Plugin","type","constructor","contentModel","options","buildModel","input","isPrivate","singularApiName","pluralApiName","modelPlugin","group","id","description","fields","isPlugin","layout","modelId","titleFieldId","noValidate","model","buildFields","validateLayout","inputFields","length","WebinyError","storageIdList","fieldIdList","fieldId","trim","field","lodashCamelCase","match","includes","storageId","createFieldStorageId","settings","childFields","push","total","row","count","filter","cell","exports","createCmsModel","createPrivateModelDefinition"],"sources":["CmsModelPlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport lodashCamelCase from \"lodash/camelCase\";\nimport camelCase from \"lodash/camelCase\";\nimport upperFirst from \"lodash/upperFirst\";\nimport pluralize from \"pluralize\";\nimport { Plugin } from \"@webiny/plugins\";\nimport {\n CmsModel as CmsModelBase,\n CmsModelField as CmsModelFieldBase,\n CmsModelFieldSettings as BaseCmsModelFieldSettings\n} from \"~/types\";\nimport { createFieldStorageId } from \"~/crud/contentModel/createFieldStorageId\";\n\nconst createApiName = (name: string) => {\n return upperFirst(camelCase(name));\n};\n\nconst createPluralApiName = (name: string) => {\n return pluralize(createApiName(name));\n};\n\ninterface CmsModelFieldSettings extends Omit<BaseCmsModelFieldSettings, \"fields\"> {\n /**\n * Object field has child fields.\n */\n fields?: CmsModelFieldInput[];\n}\n\ninterface CmsModelFieldInput extends Omit<CmsModelFieldBase, \"storageId\" | \"settings\"> {\n /**\n * If defined, it must be camelCased string.\n * This is for backwards compatibility - before fields had storageId.\n *\n * This should only be populated in old model fields.\n * News ones must have this empty.\n */\n storageId?: string;\n /**\n * We must have a possibility to have a nested field defined without the storageId.\n */\n settings?: CmsModelFieldSettings;\n}\n\nexport interface CmsApiModel\n extends Omit<\n CmsModelPluginModel,\n \"isPrivate\" | \"fields\" | \"singularApiName\" | \"pluralApiName\" | \"isPlugin\"\n > {\n isPrivate?: never;\n noValidate?: never;\n singularApiName?: string;\n pluralApiName?: string;\n fields: CmsModelFieldInput[];\n}\n\nexport interface CmsApiModelFull extends Omit<CmsApiModel, \"fields\" | \"noValidate\"> {\n noValidate: true;\n fields: CmsModelFieldBase[];\n}\n\ninterface CmsPrivateModel\n extends Omit<\n CmsModelPluginModel,\n | \"isPrivate\"\n | \"singularApiName\"\n | \"pluralApiName\"\n | \"fields\"\n | \"isPlugin\"\n | \"layout\"\n | \"titleFieldId\"\n | \"description\"\n > {\n noValidate?: never;\n titleFieldId?: string;\n singularApiName?: never;\n pluralApiName?: never;\n isPrivate: true;\n fields: CmsModelFieldInput[];\n}\n\nexport interface CmsPrivateModelFull extends Omit<CmsPrivateModel, \"fields\" | \"noValidate\"> {\n fields: CmsModelFieldBase[];\n noValidate: true;\n}\n\nexport type CmsModelInput = CmsApiModel | CmsPrivateModel | CmsApiModelFull | CmsPrivateModelFull;\n\nexport interface CmsModelPluginModel\n extends Omit<CmsModelBase, \"locale\" | \"tenant\" | \"webinyVersion\"> {\n locale?: string;\n tenant?: string;\n}\n\ninterface CmsModelPluginOptions {\n validateLayout?: boolean;\n}\n\nexport class CmsModelPlugin extends Plugin {\n public static override readonly type: string = \"cms-content-model\";\n public readonly contentModel: CmsModelPluginModel;\n\n private readonly options: CmsModelPluginOptions;\n\n constructor(contentModel: CmsModelInput, options?: CmsModelPluginOptions) {\n super();\n this.options = options || {};\n this.contentModel = this.buildModel(contentModel);\n }\n\n private buildModel(input: CmsModelInput): CmsModelPluginModel {\n const isPrivate = input.isPrivate ?? false;\n\n const singularApiName = input.singularApiName\n ? createApiName(input.singularApiName)\n : createApiName(input.name);\n\n const pluralApiName = input.pluralApiName\n ? createApiName(input.pluralApiName)\n : createPluralApiName(input.name);\n\n const modelPlugin: CmsModelPluginModel = {\n group: {\n id: \"\",\n name: \"\"\n },\n description: \"\",\n fields: [],\n isPlugin: true,\n isPrivate,\n layout: [],\n modelId: input.modelId,\n name: input.name,\n pluralApiName,\n singularApiName,\n titleFieldId: \"id\"\n };\n\n if (input.noValidate) {\n /**\n * We can safely ignore this error, because we are sure noValidate is not a model field.\n */\n // @ts-expect-error\n delete input[\"noValidate\"];\n\n return {\n ...modelPlugin,\n ...input,\n pluralApiName,\n singularApiName\n };\n }\n\n const model: CmsModelPluginModel = {\n ...modelPlugin,\n ...input,\n pluralApiName,\n singularApiName,\n fields: this.buildFields(input, input.fields)\n };\n this.validateLayout(model);\n return model;\n }\n\n private buildFields(\n model: CmsModelInput,\n inputFields: CmsModelFieldInput[]\n ): CmsModelFieldBase[] {\n if (inputFields.length === 0) {\n throw new WebinyError(\n `Missing fields for the defined model \"${model.modelId}\".`,\n \"MISSING_FIELDS\",\n {\n model\n }\n );\n }\n const fields: CmsModelFieldBase[] = [];\n const storageIdList: string[] = [];\n const fieldIdList: string[] = [];\n for (const input of inputFields) {\n /**\n * Field must contain an fieldId. It is required in the graphql, but lets check it just in case\n */\n if (!(input.fieldId || \"\").trim()) {\n throw new WebinyError(\n `Field's \"storageId\" is not defined for the content model \"${model.modelId}\".`,\n \"FIELD_ID_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n const fieldId = lodashCamelCase(input.fieldId);\n /**\n * FieldID must be in correct pattern.\n */\n if (fieldId.match(/^[0-9]/) !== null) {\n throw new WebinyError(\n `Field's \"fieldId\" does not match correct pattern in the content model \"${model.modelId}\" - cannot start with a number.`,\n \"FIELD_FIELD_ID_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n /**\n * FieldID also must be camelCased.\n */\n if (fieldId !== input.fieldId) {\n throw new WebinyError(\n `Field's \"fieldId\" must be a camel cased string in the content model \"${model.modelId}\".`,\n \"FIELD_FIELD_ID_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n /**\n * ... and fieldId must be unique.\n */\n if (fieldIdList.includes(fieldId)) {\n throw new WebinyError(\n `Field's \"fieldId\" is not unique in the content model \"${model.modelId}\".`,\n \"FIELD_ID_NOT_UNIQUE_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n\n let storageId = input.storageId ? lodashCamelCase(input.storageId) : null;\n /**\n * If defined, storageId MUST be camel cased string - for backward compatibility.\n */\n if (\n storageId &&\n (storageId.match(/^([a-zA-Z-0-9]+)$/) === null || storageId !== input.storageId)\n ) {\n throw new WebinyError(\n `Field's \"storageId\" of the field with \"fieldId\" ${input.fieldId} is not camel cased string in the content model \"${model.modelId}\".`,\n \"STORAGE_ID_NOT_CAMEL_CASED_ERROR\",\n {\n model,\n storageId,\n field: input\n }\n );\n } else if (!storageId) {\n storageId = createFieldStorageId(input);\n }\n\n /**\n * Fields storageId must be unique.\n */\n if (storageIdList.includes(storageId)) {\n throw new WebinyError(\n `Field's \"storageId\" is not unique in the content model \"${model.modelId}\".`,\n \"STORAGE_ID_ERROR\",\n {\n model,\n field: input\n }\n );\n }\n\n /**\n * We can safely ignore error because we are going through the fields and making sure each has storageId.\n */\n // @ts-expect-error\n let settings: BaseCmsModelFieldSettings = input.settings;\n\n const childFields = settings?.fields || [];\n if (input.type === \"object\" && childFields.length > 0) {\n settings = {\n ...(settings || {}),\n fields: this.buildFields(model, childFields)\n };\n }\n\n const field: CmsModelFieldBase = {\n ...input,\n settings,\n storageId\n };\n /**\n * Add all relevant data to arrays.\n */\n fields.push(field);\n storageIdList.push(field.storageId);\n fieldIdList.push(field.fieldId);\n }\n return fields;\n }\n\n private validateLayout(model: CmsModelPluginModel): void {\n /**\n * Only skip validation if option.validateLayout was set as false, explicitly.\n */\n if (this.options.validateLayout === false) {\n return;\n }\n for (const field of model.fields) {\n let total = 0;\n for (const row of model.layout) {\n const count = row.filter(cell => cell === field.id).length;\n total = total + count;\n }\n if (total === 1) {\n continue;\n } else if (total > 1) {\n throw new WebinyError(\n `Field \"${field.id}\" is in more than one layout cell.`,\n \"DUPLICATE_FIELD_IN_LAYOUT\",\n {\n model,\n field\n }\n );\n }\n throw new WebinyError(\n `Missing field \"${field.id}\" in layout.`,\n \"MISSING_FIELD_IN_LAYOUT\",\n {\n model,\n field\n }\n );\n }\n }\n}\n\nexport const createCmsModel = (\n model: CmsModelInput,\n options?: CmsModelPluginOptions\n): CmsModelPlugin => {\n return new CmsModelPlugin(model, options);\n};\n\nexport const createPrivateModelDefinition = (\n input: Omit<CmsPrivateModelFull, \"group\" | \"isPrivate\" | \"noValidate\">\n): CmsPrivateModelFull => {\n return {\n ...input,\n isPrivate: true,\n noValidate: true,\n group: {\n id: \"private\",\n name: \"Private Models\"\n }\n };\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEA,IAAAE,WAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,UAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAMA,IAAAK,qBAAA,GAAAL,OAAA;AAEA,MAAMM,aAAa,GAAIC,IAAY,IAAK;EACpC,OAAO,IAAAC,mBAAU,EAAC,IAAAC,kBAAS,EAACF,IAAI,CAAC,CAAC;AACtC,CAAC;AAED,MAAMG,mBAAmB,GAAIH,IAAY,IAAK;EAC1C,OAAO,IAAAI,kBAAS,EAACL,aAAa,CAACC,IAAI,CAAC,CAAC;AACzC,CAAC;AA8EM,MAAMK,cAAc,SAASC,eAAM,CAAC;EACvC,OAAgCC,IAAI,GAAW,mBAAmB;EAKlEC,WAAWA,CAACC,YAA2B,EAAEC,OAA+B,EAAE;IACtE,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,OAAO,GAAGA,OAAO,IAAI,CAAC,CAAC;IAC5B,IAAI,CAACD,YAAY,GAAG,IAAI,CAACE,UAAU,CAACF,YAAY,CAAC;EACrD;EAEQE,UAAUA,CAACC,KAAoB,EAAuB;IAC1D,MAAMC,SAAS,GAAGD,KAAK,CAACC,SAAS,IAAI,KAAK;IAE1C,MAAMC,eAAe,GAAGF,KAAK,CAACE,eAAe,GACvCf,aAAa,CAACa,KAAK,CAACE,eAAe,CAAC,GACpCf,aAAa,CAACa,KAAK,CAACZ,IAAI,CAAC;IAE/B,MAAMe,aAAa,GAAGH,KAAK,CAACG,aAAa,GACnChB,aAAa,CAACa,KAAK,CAACG,aAAa,CAAC,GAClCZ,mBAAmB,CAACS,KAAK,CAACZ,IAA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