@webiny/api-headless-cms 5.27.0 → 5.29.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/content/contextSetup.js.map +1 -1
  2. package/content/graphQLHandlerFactory.js.map +1 -1
  3. package/content/parameterPlugins.js.map +1 -1
  4. package/content/plugins/CmsGroupPlugin.js.map +1 -1
  5. package/content/plugins/CmsModelPlugin.js.map +1 -1
  6. package/content/plugins/CmsParametersPlugin.js.map +1 -1
  7. package/content/plugins/buildSchemaPlugins.js.map +1 -1
  8. package/content/plugins/crud/contentEntry/afterDelete.js.map +1 -1
  9. package/content/plugins/crud/contentEntry/beforeCreate.js.map +1 -1
  10. package/content/plugins/crud/contentEntry/beforeUpdate.js.map +1 -1
  11. package/content/plugins/crud/contentEntry/entryDataValidation.js.map +1 -1
  12. package/content/plugins/crud/contentEntry/markLockedFields.js.map +1 -1
  13. package/content/plugins/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
  14. package/content/plugins/crud/contentEntry.crud.js.map +1 -1
  15. package/content/plugins/crud/contentModel/afterCreate.js.map +1 -1
  16. package/content/plugins/crud/contentModel/afterCreateFrom.js.map +1 -1
  17. package/content/plugins/crud/contentModel/afterDelete.js.map +1 -1
  18. package/content/plugins/crud/contentModel/afterUpdate.js.map +1 -1
  19. package/content/plugins/crud/contentModel/beforeCreate.js +26 -4
  20. package/content/plugins/crud/contentModel/beforeCreate.js.map +1 -1
  21. package/content/plugins/crud/contentModel/beforeDelete.js.map +1 -1
  22. package/content/plugins/crud/contentModel/beforeUpdate.js +5 -188
  23. package/content/plugins/crud/contentModel/beforeUpdate.js.map +1 -1
  24. package/content/plugins/crud/contentModel/contentModelManagerFactory.js.map +1 -1
  25. package/content/plugins/crud/contentModel/createFieldModels.d.ts +2 -2
  26. package/content/plugins/crud/contentModel/createFieldModels.js +6 -2
  27. package/content/plugins/crud/contentModel/createFieldModels.js.map +1 -1
  28. package/content/plugins/crud/contentModel/idValidation.js.map +1 -1
  29. package/content/plugins/crud/contentModel/models.d.ts +1 -1
  30. package/content/plugins/crud/contentModel/models.js +43 -33
  31. package/content/plugins/crud/contentModel/models.js.map +1 -1
  32. package/content/plugins/crud/contentModel/validateLayout.d.ts +1 -1
  33. package/content/plugins/crud/contentModel/validateLayout.js +2 -3
  34. package/content/plugins/crud/contentModel/validateLayout.js.map +1 -1
  35. package/content/plugins/crud/contentModel/validateModelFields.d.ts +8 -0
  36. package/content/plugins/crud/contentModel/validateModelFields.js +201 -0
  37. package/content/plugins/crud/contentModel/validateModelFields.js.map +1 -0
  38. package/content/plugins/crud/contentModel.crud.js +7 -5
  39. package/content/plugins/crud/contentModel.crud.js.map +1 -1
  40. package/content/plugins/crud/contentModelGroup/beforeCreate.js.map +1 -1
  41. package/content/plugins/crud/contentModelGroup/beforeDelete.js.map +1 -1
  42. package/content/plugins/crud/contentModelGroup/beforeUpdate.js.map +1 -1
  43. package/content/plugins/crud/contentModelGroup.crud.js.map +1 -1
  44. package/content/plugins/crud/index.js.map +1 -1
  45. package/content/plugins/graphqlFields/boolean.js.map +1 -1
  46. package/content/plugins/graphqlFields/datetime.js.map +1 -1
  47. package/content/plugins/graphqlFields/file.js.map +1 -1
  48. package/content/plugins/graphqlFields/helpers.js.map +1 -1
  49. package/content/plugins/graphqlFields/index.js.map +1 -1
  50. package/content/plugins/graphqlFields/longText.js.map +1 -1
  51. package/content/plugins/graphqlFields/number.js.map +1 -1
  52. package/content/plugins/graphqlFields/object.js.map +1 -1
  53. package/content/plugins/graphqlFields/ref.js.map +1 -1
  54. package/content/plugins/graphqlFields/richText.js.map +1 -1
  55. package/content/plugins/graphqlFields/text.js.map +1 -1
  56. package/content/plugins/internalSecurity/InternalAuthenticationPlugin.js.map +1 -1
  57. package/content/plugins/internalSecurity/InternalAuthorizationPlugin.js.map +1 -1
  58. package/content/plugins/modelManager/DefaultCmsModelManager.js.map +1 -1
  59. package/content/plugins/modelManager/index.js.map +1 -1
  60. package/content/plugins/schema/baseSchema.js.map +1 -1
  61. package/content/plugins/schema/contentEntries.js.map +1 -1
  62. package/content/plugins/schema/contentModelGroups.js.map +1 -1
  63. package/content/plugins/schema/contentModels.js +3 -0
  64. package/content/plugins/schema/contentModels.js.map +1 -1
  65. package/content/plugins/schema/createFieldResolvers.js.map +1 -1
  66. package/content/plugins/schema/createManageResolvers.js.map +1 -1
  67. package/content/plugins/schema/createManageSDL.js.map +1 -1
  68. package/content/plugins/schema/createPreviewResolvers.js.map +1 -1
  69. package/content/plugins/schema/createReadResolvers.js.map +1 -1
  70. package/content/plugins/schema/createReadSDL.js.map +1 -1
  71. package/content/plugins/schema/resolvers/commonFieldResolvers.js.map +1 -1
  72. package/content/plugins/schema/resolvers/manage/resolveCreate.js.map +1 -1
  73. package/content/plugins/schema/resolvers/manage/resolveCreateFrom.js.map +1 -1
  74. package/content/plugins/schema/resolvers/manage/resolveDelete.js.map +1 -1
  75. package/content/plugins/schema/resolvers/manage/resolveGet.js.map +1 -1
  76. package/content/plugins/schema/resolvers/manage/resolveGetByIds.js.map +1 -1
  77. package/content/plugins/schema/resolvers/manage/resolveGetRevisions.js.map +1 -1
  78. package/content/plugins/schema/resolvers/manage/resolveList.js.map +1 -1
  79. package/content/plugins/schema/resolvers/manage/resolvePublish.js.map +1 -1
  80. package/content/plugins/schema/resolvers/manage/resolveRepublish.js.map +1 -1
  81. package/content/plugins/schema/resolvers/manage/resolveRequestChanges.js.map +1 -1
  82. package/content/plugins/schema/resolvers/manage/resolveRequestReview.js.map +1 -1
  83. package/content/plugins/schema/resolvers/manage/resolveUnpublish.js.map +1 -1
  84. package/content/plugins/schema/resolvers/manage/resolveUpdate.js.map +1 -1
  85. package/content/plugins/schema/resolvers/preview/resolveGet.js.map +1 -1
  86. package/content/plugins/schema/resolvers/preview/resolveList.js.map +1 -1
  87. package/content/plugins/schema/resolvers/read/resolveGet.js.map +1 -1
  88. package/content/plugins/schema/resolvers/read/resolveList.js.map +1 -1
  89. package/content/plugins/schema/schemaPlugins.js.map +1 -1
  90. package/content/plugins/storage/StorageTransformPlugin.js.map +1 -1
  91. package/content/plugins/storage/default.js.map +1 -1
  92. package/content/plugins/storage/object.js.map +1 -1
  93. package/content/plugins/utils/createTypeName.js.map +1 -1
  94. package/content/plugins/utils/entryStorage.js.map +1 -1
  95. package/content/plugins/utils/getEntryTitle.js.map +1 -1
  96. package/content/plugins/utils/getSchemaFromFieldPlugins.js.map +1 -1
  97. package/content/plugins/utils/pluralizedTypeName.js.map +1 -1
  98. package/content/plugins/utils/renderFields.js.map +1 -1
  99. package/content/plugins/utils/renderGetFilterFields.js.map +1 -1
  100. package/content/plugins/utils/renderInputFields.js.map +1 -1
  101. package/content/plugins/utils/renderListFilterFields.js.map +1 -1
  102. package/content/plugins/utils/renderSortEnum.js.map +1 -1
  103. package/content/plugins/validators/dateGte.js.map +1 -1
  104. package/content/plugins/validators/dateLte.js.map +1 -1
  105. package/content/plugins/validators/gte.js.map +1 -1
  106. package/content/plugins/validators/in.js.map +1 -1
  107. package/content/plugins/validators/index.js.map +1 -1
  108. package/content/plugins/validators/lte.js.map +1 -1
  109. package/content/plugins/validators/maxLength.js.map +1 -1
  110. package/content/plugins/validators/minLength.js.map +1 -1
  111. package/content/plugins/validators/pattern.js.map +1 -1
  112. package/content/plugins/validators/patternPlugins/email.js.map +1 -1
  113. package/content/plugins/validators/patternPlugins/index.js.map +1 -1
  114. package/content/plugins/validators/patternPlugins/lowerCase.js.map +1 -1
  115. package/content/plugins/validators/patternPlugins/lowerCaseSpace.js.map +1 -1
  116. package/content/plugins/validators/patternPlugins/upperCase.js.map +1 -1
  117. package/content/plugins/validators/patternPlugins/upperCaseSpace.js.map +1 -1
  118. package/content/plugins/validators/patternPlugins/url.js.map +1 -1
  119. package/content/plugins/validators/required.js.map +1 -1
  120. package/content/plugins/validators/timeGte.js.map +1 -1
  121. package/content/plugins/validators/timeLte.js.map +1 -1
  122. package/content/plugins/validators/unique.js.map +1 -1
  123. package/index.js.map +1 -1
  124. package/migrateCMSPermissions.js.map +1 -1
  125. package/package.json +26 -25
  126. package/plugins/context.js.map +1 -1
  127. package/plugins/crud/index.js.map +1 -1
  128. package/plugins/crud/settings.crud.js.map +1 -1
  129. package/plugins/crud/system.crud.js.map +1 -1
  130. package/plugins/graphql/system.js.map +1 -1
  131. package/plugins/graphql.js.map +1 -1
  132. package/plugins/upgrades/index.js.map +1 -1
  133. package/plugins/upgrades/v5.5.0/helpers.js.map +1 -1
  134. package/plugins/upgrades/v5.5.0/index.js.map +1 -1
  135. package/transformers.js.map +1 -1
  136. package/types.d.ts +20 -0
  137. package/types.js.map +1 -1
  138. package/utils.js.map +1 -1
@@ -1,119 +1,11 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports.assignBeforeModelUpdate = void 0;
9
7
 
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
13
-
14
- var _error = _interopRequireDefault(require("@webiny/error"));
15
-
16
- var _CmsModelPlugin = require("../../CmsModelPlugin");
17
-
18
- var _createManageSDL = require("../../schema/createManageSDL");
19
-
20
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
21
-
22
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
23
-
24
- const defaultTitleFieldId = "id";
25
- const allowedTitleFieldTypes = ["text", "number"];
26
-
27
- const getContentModelTitleFieldId = (fields, titleFieldId) => {
28
- // if there is no title field defined either in input data or existing content model data
29
- // we will take first text field that has no multiple values enabled
30
- // or if initial titleFieldId is the default one also try to find first available text field
31
- if (!titleFieldId || titleFieldId === defaultTitleFieldId) {
32
- const titleField = fields.find(field => {
33
- return field.type === "text" && !field.multipleValues;
34
- });
35
- return titleField ? titleField.fieldId : defaultTitleFieldId;
36
- } // check existing titleFieldId for existence in the model
37
- // for correct type
38
- // and that it is not multiple values field
39
-
40
-
41
- const target = fields.find(f => f.fieldId === titleFieldId);
42
-
43
- if (!target) {
44
- throw new _error.default(`Field does not exist in the model.`, "VALIDATION_ERROR", {
45
- fieldId: titleFieldId,
46
- fields
47
- });
48
- }
49
-
50
- if (allowedTitleFieldTypes.includes(target.type) === false) {
51
- throw new _error.default(`Only ${allowedTitleFieldTypes.join(", ")} and id fields can be used as an entry title.`, "ENTRY_TITLE_FIELD_TYPE", {
52
- fieldId: target.fieldId,
53
- type: target.type
54
- });
55
- }
56
-
57
- if (target.multipleValues) {
58
- throw new _error.default(`Fields that accept multiple values cannot be used as the entry title.`, "ENTRY_TITLE_FIELD_TYPE", {
59
- fieldId: target.fieldId,
60
- type: target.type
61
- });
62
- }
63
-
64
- return target.fieldId;
65
- };
66
-
67
- const extractInvalidField = (model, err) => {
68
- var _err$source;
69
-
70
- const sdl = ((_err$source = err.source) === null || _err$source === void 0 ? void 0 : _err$source.body) || ""; // Find the invalid type
71
-
72
- const {
73
- line: lineNumber
74
- } = err.locations ? err.locations[0] : {
75
- line: 0
76
- };
77
- const sdlLines = sdl.split("\n");
78
- let sdlLine;
79
- let gqlType;
80
-
81
- for (let i = lineNumber; i > 0; i--) {
82
- if (sdlLine && sdlLine.includes("type ")) {
83
- gqlType = sdlLine.match(/type\s+(.*?)\s+{/);
84
- break;
85
- }
86
-
87
- sdlLine = sdlLines[i];
88
- }
89
-
90
- let invalidField = undefined;
91
-
92
- if (Array.isArray(gqlType)) {
93
- const fieldRegex = new RegExp(`([^\\s+].*?):\\s+\\[?${gqlType[1]}!?\\]?`);
94
- const matched = sdl.match(fieldRegex);
95
-
96
- if (matched) {
97
- invalidField = matched[1];
98
- }
99
- }
100
-
101
- let message = `See more details in the browser console.`;
102
-
103
- if (invalidField) {
104
- message = `Please review the definition of "${invalidField}" field.`;
105
- }
106
-
107
- return {
108
- data: {
109
- modelId: model.modelId,
110
- sdl,
111
- invalidField
112
- },
113
- code: "INVALID_MODEL_DEFINITION",
114
- message: [`Model "${model.modelId}" was not saved!`, message].join("\n")
115
- };
116
- };
8
+ var _validateModelFields = require("./validateModelFields");
117
9
 
118
10
  const assignBeforeModelUpdate = params => {
119
11
  const {
@@ -121,85 +13,10 @@ const assignBeforeModelUpdate = params => {
121
13
  plugins
122
14
  } = params;
123
15
  onBeforeModelUpdate.subscribe(async params => {
124
- const {
125
- model
126
- } = params;
127
- const modelPlugin = plugins.byType(_CmsModelPlugin.CmsModelPlugin.type).find(item => item.contentModel.modelId === model.modelId);
128
-
129
- if (modelPlugin) {
130
- throw new _error.default("Content models defined via plugins cannot be updated.", "CONTENT_MODEL_UPDATE_ERROR", {
131
- modelId: model.modelId
132
- });
133
- }
134
-
135
- const {
136
- titleFieldId
137
- } = model; // There should be fields/locked fields in either model or data to be updated.
138
-
139
- const {
140
- fields = [],
141
- lockedFields = []
142
- } = model; // Let's inspect the fields of the received content model. We prevent saving of a content model if it
143
- // contains a field for which a "cms-model-field-to-graphql" plugin does not exist on the backend.
144
-
145
- const fieldTypePlugins = plugins.byType("cms-model-field-to-graphql");
146
-
147
- for (let i = 0; i < fields.length; i++) {
148
- const field = fields[i];
149
-
150
- if (!fieldTypePlugins.find(item => item.fieldType === field.type)) {
151
- throw new Error(`Cannot update content model because of the unknown "${field.type}" field.`);
152
- }
153
- }
154
-
155
- if (fields.length) {
156
- // Make sure that this model can be safely converted to a GraphQL SDL
157
- const schema = (0, _createManageSDL.createManageSDL)({
158
- model,
159
- fieldTypePlugins: fieldTypePlugins.reduce((acc, pl) => _objectSpread(_objectSpread({}, acc), {}, {
160
- [pl.fieldType]: pl
161
- }), {})
162
- });
163
-
164
- try {
165
- (0, _graphqlTag.default)(schema);
166
- } catch (err) {
167
- throw new _error.default(extractInvalidField(model, err));
168
- }
169
- }
170
-
171
- model.titleFieldId = getContentModelTitleFieldId(fields, titleFieldId);
172
- const cmsLockedFieldPlugins = plugins.byType("cms-model-locked-field"); // We must not allow removal or changes in fields that are already in use in content entries.
173
-
174
- for (const lockedField of lockedFields) {
175
- const existingField = fields.find(item => item.fieldId === lockedField.fieldId);
176
-
177
- if (!existingField) {
178
- throw new _error.default(`Cannot remove the field "${lockedField.fieldId}" because it's already in use in created content.`, "ENTRY_FIELD_USED");
179
- }
180
-
181
- if (lockedField.multipleValues !== existingField.multipleValues) {
182
- throw new _error.default(`Cannot change "multipleValues" for the "${lockedField.fieldId}" field because it's already in use in created content.`, "ENTRY_FIELD_USED");
183
- }
184
-
185
- if (lockedField.type !== existingField.type) {
186
- 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");
187
- } // Check `lockedField` invariant for specific field
188
-
189
-
190
- const lockedFieldsByType = cmsLockedFieldPlugins.filter(pl => pl.fieldType === lockedField.type);
191
-
192
- for (const plugin of lockedFieldsByType) {
193
- if (typeof plugin.checkLockedField !== "function") {
194
- continue;
195
- }
196
-
197
- plugin.checkLockedField({
198
- lockedField,
199
- field: existingField
200
- });
201
- }
202
- }
16
+ await (0, _validateModelFields.validateModelFields)({
17
+ model: params.model,
18
+ plugins
19
+ });
203
20
  });
204
21
  };
205
22
 
@@ -1 +1 @@
1
- {"version":3,"sources":["beforeUpdate.ts"],"names":["defaultTitleFieldId","allowedTitleFieldTypes","getContentModelTitleFieldId","fields","titleFieldId","titleField","find","field","type","multipleValues","fieldId","target","f","WebinyError","includes","join","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","assignBeforeModelUpdate","params","onBeforeModelUpdate","plugins","subscribe","modelPlugin","byType","CmsModelPlugin","item","contentModel","lockedFields","fieldTypePlugins","length","fieldType","Error","schema","reduce","acc","pl","cmsLockedFieldPlugins","lockedField","existingField","lockedFieldsByType","filter","plugin","checkLockedField"],"mappings":";;;;;;;;;;;AACA;;AAUA;;AACA;;AACA;;;;;;AAGA,MAAMA,mBAAmB,GAAG,IAA5B;AAEA,MAAMC,sBAAsB,GAAG,CAAC,MAAD,EAAS,QAAT,CAA/B;;AAEA,MAAMC,2BAA2B,GAAG,CAACC,MAAD,EAA0BC,YAA1B,KAA4D;AAC5F;AACA;AACA;AACA,MAAI,CAACA,YAAD,IAAiBA,YAAY,KAAKJ,mBAAtC,EAA2D;AACvD,UAAMK,UAAU,GAAGF,MAAM,CAACG,IAAP,CAAYC,KAAK,IAAI;AACpC,aAAOA,KAAK,CAACC,IAAN,KAAe,MAAf,IAAyB,CAACD,KAAK,CAACE,cAAvC;AACH,KAFkB,CAAnB;AAGA,WAAOJ,UAAU,GAAGA,UAAU,CAACK,OAAd,GAAwBV,mBAAzC;AACH,GAT2F,CAU5F;AACA;AACA;;;AACA,QAAMW,MAAM,GAAGR,MAAM,CAACG,IAAP,CAAYM,CAAC,IAAIA,CAAC,CAACF,OAAF,KAAcN,YAA/B,CAAf;;AACA,MAAI,CAACO,MAAL,EAAa;AACT,UAAM,IAAIE,cAAJ,CAAiB,oCAAjB,EAAsD,kBAAtD,EAA0E;AAC5EH,MAAAA,OAAO,EAAEN,YADmE;AAE5ED,MAAAA;AAF4E,KAA1E,CAAN;AAIH;;AAED,MAAIF,sBAAsB,CAACa,QAAvB,CAAgCH,MAAM,CAACH,IAAvC,MAAiD,KAArD,EAA4D;AACxD,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AAO,CAACG,MAAR,CAA0C,wBAA1C,CADJ,CAxD0C,CA2D1C;;AACA,SAAK,MAAMc,WAAX,IAA0BV,YAA1B,EAAwC;AACpC,YAAMW,aAAa,GAAG5D,MAAM,CAACG,IAAP,CAAY4C,IAAI,IAAIA,IAAI,CAACxC,OAAL,KAAiBoD,WAAW,CAACpD,OAAjD,CAAtB;;AACA,UAAI,CAACqD,aAAL,EAAoB;AAChB,cAAM,IAAIlD,cAAJ,CACD,4BAA2BiD,WAAW,CAACpD,OAAQ,mDAD9C,EAEF,kBAFE,CAAN;AAIH;;AAED,UAAIoD,WAAW,CAACrD,cAAZ,KAA+BsD,aAAa,CAACtD,cAAjD,EAAiE;AAC7D,cAAM,IAAII,cAAJ,CACD,2CAA0CiD,WAAW,CAACpD,OAAQ,yDAD7D,EAEF,kBAFE,CAAN;AAIH;;AAED,UAAIoD,WAAW,CAACtD,IAAZ,KAAqBuD,aAAa,CAACvD,IAAvC,EAA6C;AACzC,cAAM,IAAIK,cAAJ,CACD,qCAAoCiD,WAAW,CAACpD,OAAQ,yDADvD,EAEF,kBAFE,CAAN;AAIH,OArBmC,CAuBpC;;;AACA,YAAMsD,kBAAkB,GAAGH,qBAAqB,CAACI,MAAtB,CACvBL,EAAE,IAAIA,EAAE,CAACL,SAAH,KAAiBO,WAAW,CAACtD,IADZ,CAA3B;;AAGA,WAAK,MAAM0D,MAAX,IAAqBF,kBAArB,EAAyC;AACrC,YAAI,OAAOE,MAAM,CAACC,gBAAd,KAAmC,UAAvC,EAAmD;AAC/C;AACH;;AACDD,QAAAA,MAAM,CAACC,gBAAP,CAAwB;AACpBL,UAAAA,WADoB;AAEpBvD,UAAAA,KAAK,EAAEwD;AAFa,SAAxB;AAIH;AACJ;AACJ,GAjGD;AAkGH,CArGM","sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport gql from \"graphql-tag\";\nimport {\n BeforeModelUpdateTopicParams,\n CmsModel,\n CmsModelField,\n CmsModelFieldToGraphQLPlugin,\n CmsModelLockedFieldPlugin,\n HeadlessCmsStorageOperations\n} from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport WebinyError from \"@webiny/error\";\nimport { CmsModelPlugin } from \"~/content/plugins/CmsModelPlugin\";\nimport { createManageSDL } from \"~/content/plugins/schema/createManageSDL\";\nimport { GraphQLError } from \"graphql\";\n\nconst defaultTitleFieldId = \"id\";\n\nconst allowedTitleFieldTypes = [\"text\", \"number\"];\n\nconst getContentModelTitleFieldId = (fields: CmsModelField[], titleFieldId?: string): string => {\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 if (!titleFieldId || titleFieldId === defaultTitleFieldId) {\n const titleField = fields.find(field => {\n return field.type === \"text\" && !field.multipleValues;\n });\n return titleField ? titleField.fieldId : defaultTitleFieldId;\n }\n // check existing titleFieldId for existence in the model\n // for correct type\n // and that it is not multiple values field\n const target = fields.find(f => f.fieldId === titleFieldId);\n if (!target) {\n throw new WebinyError(`Field does not exist in the model.`, \"VALIDATION_ERROR\", {\n fieldId: titleFieldId,\n fields\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 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 fieldId: target.fieldId,\n type: target.type\n }\n );\n }\n\n return target.fieldId;\n};\n\ninterface AssignBeforeModelUpdateParams {\n onBeforeModelUpdate: Topic<BeforeModelUpdateTopicParams>;\n storageOperations: HeadlessCmsStorageOperations;\n plugins: PluginsContainer;\n}\n\nconst extractInvalidField = (model: CmsModel, err: GraphQLError) => {\n const sdl = err.source?.body || \"\";\n\n // Find the invalid type\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\nexport const assignBeforeModelUpdate = (params: AssignBeforeModelUpdateParams) => {\n const { onBeforeModelUpdate, plugins } = params;\n\n onBeforeModelUpdate.subscribe(async params => {\n const { model } = 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 const { titleFieldId } = model;\n\n // There should be fields/locked fields in either model or data to be updated.\n const { fields = [], lockedFields = [] } = model;\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 const fieldTypePlugins = plugins.byType<CmsModelFieldToGraphQLPlugin>(\n \"cms-model-field-to-graphql\"\n );\n\n for (let i = 0; i < fields.length; i++) {\n const field = fields[i];\n if (!fieldTypePlugins.find(item => item.fieldType === field.type)) {\n throw new Error(\n `Cannot update content model because of the unknown \"${field.type}\" field.`\n );\n }\n }\n\n if (fields.length) {\n // Make sure that this model can be safely converted to a GraphQL SDL\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 // We must not allow removal or changes in fields that are already in use in content entries.\n for (const lockedField of lockedFields) {\n const existingField = fields.find(item => item.fieldId === lockedField.fieldId);\n if (!existingField) {\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 }\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 }\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 }\n\n // Check `lockedField` invariant for specific field\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};\n"]}
1
+ {"version":3,"names":["assignBeforeModelUpdate","params","onBeforeModelUpdate","plugins","subscribe","validateModelFields","model"],"sources":["beforeUpdate.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { BeforeModelUpdateTopicParams, HeadlessCmsStorageOperations } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { validateModelFields } from \"~/content/plugins/crud/contentModel/validateModelFields\";\n\ninterface AssignBeforeModelUpdateParams {\n onBeforeModelUpdate: Topic<BeforeModelUpdateTopicParams>;\n storageOperations: HeadlessCmsStorageOperations;\n plugins: PluginsContainer;\n}\n\nexport const assignBeforeModelUpdate = (params: AssignBeforeModelUpdateParams) => {\n const { onBeforeModelUpdate, plugins } = params;\n\n onBeforeModelUpdate.subscribe(async params => {\n await validateModelFields({\n model: params.model,\n plugins\n });\n });\n};\n"],"mappings":";;;;;;;AAGA;;AAQO,MAAMA,uBAAuB,GAAIC,MAAD,IAA2C;EAC9E,MAAM;IAAEC,mBAAF;IAAuBC;EAAvB,IAAmCF,MAAzC;EAEAC,mBAAmB,CAACE,SAApB,CAA8B,MAAMH,MAAN,IAAgB;IAC1C,MAAM,IAAAI,wCAAA,EAAoB;MACtBC,KAAK,EAAEL,MAAM,CAACK,KADQ;MAEtBH;IAFsB,CAApB,CAAN;EAIH,CALD;AAMH,CATM"}
@@ -1 +1 @@
1
- {"version":3,"sources":["contentModelManagerFactory.ts"],"names":["defaultName","contentModelManagerFactory","context","model","pluginsByType","plugins","byType","reverse","plugin","target","Array","isArray","modelId","includes","name","create","find","Error"],"mappings":";;;;;;AAEA,MAAMA,WAAW,GAAG,+BAApB;;AAEO,MAAMC,0BAA0B,GAAG,OACtCC,OADsC,EAEtCC,KAFsC,KAGX;AAC3B,QAAMC,aAAa,GAAGF,OAAO,CAACG,OAAR,CACjBC,MADiB,CACU,2BADV,EAEjBC,OAFiB,EAAtB;;AAGA,OAAK,MAAMC,MAAX,IAAqBJ,aAArB,EAAoC;AAChC,UAAMK,MAAM,GAAGC,KAAK,CAACC,OAAN,CAAcH,MAAM,CAACI,OAArB,IAAgCJ,MAAM,CAACI,OAAvC,GAAiD,CAACJ,MAAM,CAACI,OAAR,CAAhE;;AACA,QAAIH,MAAM,CAACI,QAAP,CAAgBV,KAAK,CAACS,OAAtB,MAAmC,IAAnC,IAA2CJ,MAAM,CAACM,IAAP,KAAgBd,WAA/D,EAA4E;AACxE,aAAO,MAAMQ,MAAM,CAACO,MAAP,CAAcb,OAAd,EAAuBC,KAAvB,CAAb;AACH;AACJ;;AACD,QAAMK,MAAM,GAAGJ,aAAa,CAACY,IAAd,CAAmBR,MAAM,IAAIA,MAAM,CAACM,IAAP,KAAgBd,WAA7C,CAAf;;AACA,MAAI,CAACQ,MAAL,EAAa;AACT,UAAM,IAAIS,KAAJ,CAAU,sDAAV,CAAN;AACH;;AACD,SAAO,MAAMT,MAAM,CAACO,MAAP,CAAcb,OAAd,EAAuBC,KAAvB,CAAb;AACH,CAlBM","sourcesContent":["import { CmsModel, CmsContext, ModelManagerPlugin, CmsModelManager } from \"~/types\";\n\nconst defaultName = \"content-model-manager-default\";\n\nexport const contentModelManagerFactory = async (\n context: CmsContext,\n model: CmsModel\n): Promise<CmsModelManager> => {\n const pluginsByType = context.plugins\n .byType<ModelManagerPlugin>(\"cms-content-model-manager\")\n .reverse();\n for (const plugin of pluginsByType) {\n const target = Array.isArray(plugin.modelId) ? plugin.modelId : [plugin.modelId];\n if (target.includes(model.modelId) === true && plugin.name !== defaultName) {\n return await plugin.create(context, model);\n }\n }\n const plugin = pluginsByType.find(plugin => plugin.name === defaultName);\n if (!plugin) {\n throw new Error(\"There is no default plugin to create CmsModelManager\");\n }\n return await plugin.create(context, model);\n};\n"]}
1
+ {"version":3,"names":["defaultName","contentModelManagerFactory","context","model","pluginsByType","plugins","byType","reverse","plugin","target","Array","isArray","modelId","includes","name","create","find","Error"],"sources":["contentModelManagerFactory.ts"],"sourcesContent":["import { CmsModel, CmsContext, ModelManagerPlugin, CmsModelManager } from \"~/types\";\n\nconst defaultName = \"content-model-manager-default\";\n\nexport const contentModelManagerFactory = async (\n context: CmsContext,\n model: CmsModel\n): Promise<CmsModelManager> => {\n const pluginsByType = context.plugins\n .byType<ModelManagerPlugin>(\"cms-content-model-manager\")\n .reverse();\n for (const plugin of pluginsByType) {\n const target = Array.isArray(plugin.modelId) ? plugin.modelId : [plugin.modelId];\n if (target.includes(model.modelId) === true && plugin.name !== defaultName) {\n return await plugin.create(context, model);\n }\n }\n const plugin = pluginsByType.find(plugin => plugin.name === defaultName);\n if (!plugin) {\n throw new Error(\"There is no default plugin to create CmsModelManager\");\n }\n return await plugin.create(context, model);\n};\n"],"mappings":";;;;;;AAEA,MAAMA,WAAW,GAAG,+BAApB;;AAEO,MAAMC,0BAA0B,GAAG,OACtCC,OADsC,EAEtCC,KAFsC,KAGX;EAC3B,MAAMC,aAAa,GAAGF,OAAO,CAACG,OAAR,CACjBC,MADiB,CACU,2BADV,EAEjBC,OAFiB,EAAtB;;EAGA,KAAK,MAAMC,MAAX,IAAqBJ,aAArB,EAAoC;IAChC,MAAMK,MAAM,GAAGC,KAAK,CAACC,OAAN,CAAcH,MAAM,CAACI,OAArB,IAAgCJ,MAAM,CAACI,OAAvC,GAAiD,CAACJ,MAAM,CAACI,OAAR,CAAhE;;IACA,IAAIH,MAAM,CAACI,QAAP,CAAgBV,KAAK,CAACS,OAAtB,MAAmC,IAAnC,IAA2CJ,MAAM,CAACM,IAAP,KAAgBd,WAA/D,EAA4E;MACxE,OAAO,MAAMQ,MAAM,CAACO,MAAP,CAAcb,OAAd,EAAuBC,KAAvB,CAAb;IACH;EACJ;;EACD,MAAMK,MAAM,GAAGJ,aAAa,CAACY,IAAd,CAAmBR,MAAM,IAAIA,MAAM,CAACM,IAAP,KAAgBd,WAA7C,CAAf;;EACA,IAAI,CAACQ,MAAL,EAAa;IACT,MAAM,IAAIS,KAAJ,CAAU,sDAAV,CAAN;EACH;;EACD,OAAO,MAAMT,MAAM,CAACO,MAAP,CAAcb,OAAd,EAAuBC,KAAvB,CAAb;AACH,CAlBM"}
@@ -1,2 +1,2 @@
1
- import { CmsModelField, CmsModel, CmsModelUpdateInput } from "../../../../types";
2
- export declare const createFieldModels: (_: CmsModel, data: CmsModelUpdateInput) => Promise<CmsModelField[]>;
1
+ import { CmsModelField, CmsModelFieldInput } from "../../../../types";
2
+ export declare const createFieldModels: (input?: CmsModelFieldInput[] | undefined) => Promise<CmsModelField[]>;
@@ -7,10 +7,14 @@ exports.createFieldModels = void 0;
7
7
 
8
8
  var _models = require("./models");
9
9
 
10
- const createFieldModels = async (_, data) => {
10
+ const createFieldModels = async input => {
11
+ if (!input || input.length === 0) {
12
+ return [];
13
+ }
14
+
11
15
  const fields = [];
12
16
 
13
- for (const field of data.fields) {
17
+ for (const field of input) {
14
18
  const fieldData = new _models.ContentModelFieldModel().populate(field);
15
19
  await fieldData.validate();
16
20
  fields.push(await fieldData.toJSON());
@@ -1 +1 @@
1
- {"version":3,"sources":["createFieldModels.ts"],"names":["createFieldModels","_","data","fields","field","fieldData","ContentModelFieldModel","populate","validate","push","toJSON"],"mappings":";;;;;;;AACA;;AAEO,MAAMA,iBAAiB,GAAG,OAC7BC,CAD6B,EAE7BC,IAF6B,KAGF;AAC3B,QAAMC,MAAuB,GAAG,EAAhC;;AACA,OAAK,MAAMC,KAAX,IAAoBF,IAAI,CAACC,MAAzB,EAAiC;AAC7B,UAAME,SAAS,GAAG,IAAIC,8BAAJ,GAA6BC,QAA7B,CAAsCH,KAAtC,CAAlB;AACA,UAAMC,SAAS,CAACG,QAAV,EAAN;AACAL,IAAAA,MAAM,CAACM,IAAP,CAAY,MAAMJ,SAAS,CAACK,MAAV,EAAlB;AACH;;AACD,SAAOP,MAAP;AACH,CAXM","sourcesContent":["import { CmsModelField, CmsModel, CmsModelUpdateInput } from \"~/types\";\nimport { ContentModelFieldModel } from \"./models\";\n\nexport const createFieldModels = async (\n _: CmsModel,\n data: CmsModelUpdateInput\n): Promise<CmsModelField[]> => {\n const fields: CmsModelField[] = [];\n for (const field of data.fields) {\n const fieldData = new ContentModelFieldModel().populate(field);\n await fieldData.validate();\n fields.push(await fieldData.toJSON());\n }\n return fields;\n};\n"]}
1
+ {"version":3,"names":["createFieldModels","input","length","fields","field","fieldData","ContentModelFieldModel","populate","validate","push","toJSON"],"sources":["createFieldModels.ts"],"sourcesContent":["import { CmsModelField, CmsModelFieldInput } from \"~/types\";\nimport { ContentModelFieldModel } from \"./models\";\n\nexport const createFieldModels = async (input?: CmsModelFieldInput[]): Promise<CmsModelField[]> => {\n if (!input || input.length === 0) {\n return [];\n }\n const fields: CmsModelField[] = [];\n for (const field of input) {\n const fieldData = new ContentModelFieldModel().populate(field);\n await fieldData.validate();\n fields.push(await fieldData.toJSON());\n }\n return fields;\n};\n"],"mappings":";;;;;;;AACA;;AAEO,MAAMA,iBAAiB,GAAG,MAAOC,KAAP,IAAkE;EAC/F,IAAI,CAACA,KAAD,IAAUA,KAAK,CAACC,MAAN,KAAiB,CAA/B,EAAkC;IAC9B,OAAO,EAAP;EACH;;EACD,MAAMC,MAAuB,GAAG,EAAhC;;EACA,KAAK,MAAMC,KAAX,IAAoBH,KAApB,EAA2B;IACvB,MAAMI,SAAS,GAAG,IAAIC,8BAAJ,GAA6BC,QAA7B,CAAsCH,KAAtC,CAAlB;IACA,MAAMC,SAAS,CAACG,QAAV,EAAN;IACAL,MAAM,CAACM,IAAP,CAAY,MAAMJ,SAAS,CAACK,MAAV,EAAlB;EACH;;EACD,OAAOP,MAAP;AACH,CAXM"}
@@ -1 +1 @@
1
- {"version":3,"sources":["idValidation.ts"],"names":["value","validation","validate","charAt","match","Error","trim","toLowerCase"],"mappings":";;;;;;;AAAA;;eAEe,MAAOA,KAAP,IAAwC;AACnD,QAAMC,uBAAWC,QAAX,CAAoBF,KAApB,EAA2B,wBAA3B,CAAN;;AACA,MAAI,CAACA,KAAK,CAACG,MAAN,CAAa,CAAb,EAAgBC,KAAhB,CAAsB,UAAtB,CAAL,EAAwC;AACpC,UAAM,IAAIC,KAAJ,CAAW,eAAcL,KAAM,+CAA/B,CAAN;AACH;;AACD,MAAIA,KAAK,CAACM,IAAN,GAAaC,WAAb,OAA+B,IAAnC,EAAyC;AACrC,UAAM,IAAIF,KAAJ,CAAW,eAAcL,KAAM,kDAA/B,CAAN;AACH;AACJ,C","sourcesContent":["import { validation } from \"@webiny/validation\";\n\nexport default async (value: string): Promise<void> => {\n await validation.validate(value, \"required,maxLength:100\");\n if (!value.charAt(0).match(/[a-zA-Z]/)) {\n throw new Error(`Provided ID ${value} is not valid - must not start with a number.`);\n }\n if (value.trim().toLowerCase() === \"id\") {\n throw new Error(`Provided ID ${value} is not valid - \"id\" is an auto-generated field.`);\n }\n};\n"]}
1
+ {"version":3,"names":["value","validation","validate","charAt","match","Error","trim","toLowerCase"],"sources":["idValidation.ts"],"sourcesContent":["import { validation } from \"@webiny/validation\";\n\nexport default async (value: string): Promise<void> => {\n await validation.validate(value, \"required,maxLength:100\");\n if (!value.charAt(0).match(/[a-zA-Z]/)) {\n throw new Error(`Provided ID ${value} is not valid - must not start with a number.`);\n }\n if (value.trim().toLowerCase() === \"id\") {\n throw new Error(`Provided ID ${value} is not valid - \"id\" is an auto-generated field.`);\n }\n};\n"],"mappings":";;;;;;;AAAA;;eAEe,MAAOA,KAAP,IAAwC;EACnD,MAAMC,sBAAA,CAAWC,QAAX,CAAoBF,KAApB,EAA2B,wBAA3B,CAAN;;EACA,IAAI,CAACA,KAAK,CAACG,MAAN,CAAa,CAAb,EAAgBC,KAAhB,CAAsB,UAAtB,CAAL,EAAwC;IACpC,MAAM,IAAIC,KAAJ,CAAW,eAAcL,KAAM,+CAA/B,CAAN;EACH;;EACD,IAAIA,KAAK,CAACM,IAAN,GAAaC,WAAb,OAA+B,IAAnC,EAAyC;IACrC,MAAM,IAAIF,KAAJ,CAAW,eAAcL,KAAM,kDAA/B,CAAN;EACH;AACJ,C"}
@@ -1,4 +1,4 @@
1
+ export declare const ContentModelFieldModel: any;
1
2
  export declare const CreateContentModelModel: any;
2
3
  export declare const CreateContentModelModelFrom: any;
3
- export declare const ContentModelFieldModel: any;
4
4
  export declare const UpdateContentModelModel: any;
@@ -30,39 +30,6 @@ const requiredShortString = _validation.validation.create("required,maxLength:25
30
30
 
31
31
  const shortString = _validation.validation.create("maxLength:255");
32
32
 
33
- const CreateContentModelModel = (0, _fields.withFields)({
34
- name: (0, _fields.string)({
35
- validation: requiredShortString
36
- }),
37
- modelId: (0, _fields.string)({
38
- validation: shortString
39
- }),
40
- description: (0, _fields.string)({
41
- validation: shortString
42
- }),
43
- group: (0, _fields.string)({
44
- validation: requiredShortString
45
- })
46
- })();
47
- exports.CreateContentModelModel = CreateContentModelModel;
48
- const CreateContentModelModelFrom = (0, _fields.withFields)({
49
- name: (0, _fields.string)({
50
- validation: requiredShortString
51
- }),
52
- modelId: (0, _fields.string)({
53
- validation: shortString
54
- }),
55
- description: (0, _fields.string)({
56
- validation: shortString
57
- }),
58
- group: (0, _fields.string)({
59
- validation: requiredShortString
60
- }),
61
- locale: (0, _fields.string)({
62
- validation: shortString
63
- })
64
- })();
65
- exports.CreateContentModelModelFrom = CreateContentModelModelFrom;
66
33
  const RendererModel = (0, _fields.withFields)({
67
34
  name: (0, _fields.string)({
68
35
  validation: requiredShortString
@@ -144,6 +111,49 @@ const ContentModelFieldModel = (0, _fields.withFields)({
144
111
  })
145
112
  })();
146
113
  exports.ContentModelFieldModel = ContentModelFieldModel;
114
+ const CreateContentModelModel = (0, _fields.withFields)({
115
+ name: (0, _fields.string)({
116
+ validation: requiredShortString
117
+ }),
118
+ modelId: (0, _fields.string)({
119
+ validation: shortString
120
+ }),
121
+ description: (0, _fields.string)({
122
+ validation: shortString
123
+ }),
124
+ group: (0, _fields.string)({
125
+ validation: requiredShortString
126
+ }),
127
+ fields: (0, _fields.fields)({
128
+ instanceOf: ContentModelFieldModel,
129
+ value: [],
130
+ list: true,
131
+ required: true
132
+ }),
133
+ layout: (0, _commodoFieldsObject.object)({
134
+ value: [],
135
+ required: true
136
+ })
137
+ })();
138
+ exports.CreateContentModelModel = CreateContentModelModel;
139
+ const CreateContentModelModelFrom = (0, _fields.withFields)({
140
+ name: (0, _fields.string)({
141
+ validation: requiredShortString
142
+ }),
143
+ modelId: (0, _fields.string)({
144
+ validation: shortString
145
+ }),
146
+ description: (0, _fields.string)({
147
+ validation: shortString
148
+ }),
149
+ group: (0, _fields.string)({
150
+ validation: requiredShortString
151
+ }),
152
+ locale: (0, _fields.string)({
153
+ validation: shortString
154
+ })
155
+ })();
156
+ exports.CreateContentModelModelFrom = CreateContentModelModelFrom;
147
157
  const UpdateContentModelModel = (0, _fields.withFields)({
148
158
  name: (0, _fields.string)({
149
159
  validation: shortString
@@ -1 +1 @@
1
- {"version":3,"sources":["models.ts"],"names":["requiredShortString","validation","create","shortString","CreateContentModelModel","name","modelId","description","group","CreateContentModelModelFrom","locale","RendererModel","ContentModelFieldModel","id","fieldId","value","trim","idValidation","label","helpText","placeholderText","type","multipleValues","predefinedValues","instanceOf","enabled","values","list","selected","renderer","message","settings","listValidation","UpdateContentModelModel","titleFieldId","fields","required","layout"],"mappings":";;;;;;;;;AAAA;;AACA;;AAKA;;AAKA;;AACA;;AAVA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AAIA,MAAMA,mBAAmB,GAAGC,uBAAWC,MAAX,CAAkB,wBAAlB,CAA5B;;AACA,MAAMC,WAAW,GAAGF,uBAAWC,MAAX,CAAkB,eAAlB,CAApB;;AAEO,MAAME,uBAAuB,GAAG,wBAAW;AAC9CC,EAAAA,IAAI,EAAE,oBAAO;AAAEJ,IAAAA,UAAU,EAAED;AAAd,GAAP,CADwC;AAE9CM,EAAAA,OAAO,EAAE,oBAAO;AAAEL,IAAAA,UAAU,EAAEE;AAAd,GAAP,CAFqC;AAG9CI,EAAAA,WAAW,EAAE,oBAAO;AAAEN,IAAAA,UAAU,EAAEE;AAAd,GAAP,CAHiC;AAI9CK,EAAAA,KAAK,EAAE,oBAAO;AAAEP,IAAAA,UAAU,EAAED;AAAd,GAAP;AAJuC,CAAX,GAAhC;;AAOA,MAAMS,2BAA2B,GAAG,wBAAW;AAClDJ,EAAAA,IAAI,EAAE,oBAAO;AAAEJ,IAAAA,UAAU,EAAED;AAAd,GAAP,CAD4C;AAElDM,EAAAA,OAAO,EAAE,oBA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AAK,EAAE;AAAT,OAAP;AAHS,KAAX;AAHO,GAAP,CApC6B;AA6C7CgB,EAAAA,QAAQ,EAAE,iCAAO;AAAEhB,IAAAA,KAAK,EAAE;AAAT,GAAP;AA7CmC,CAAX,GAA/B;;AAgDA,MAAMkB,uBAAuB,GAAG,wBAAW;AAC9C5B,EAAAA,IAAI,EAAE,oBAAO;AAAEJ,IAAAA,UAAU,EAAEE;AAAd,GAAP,CADwC;AAE9CI,EAAAA,WAAW,EAAE,oBAAO;AAAEN,IAAAA,UAAU,EAAEE;AAAd,GAAP,CAFiC;AAG9CK,EAAAA,KAAK,EAAE,oBAAO;AAAEP,IAAAA,UAAU,EAAEE;AAAd,GAAP,CAHuC;AAI9C+B,EAAAA,YAAY,EAAE,qBAJgC;AAK9CC,EAAAA,MAAM,EAAE,oBAAO;AAAEX,IAAAA,UAAU,EAAEZ,sBAAd;AAAsCG,IAAAA,KAAK,EAAE,EAA7C;AAAiDY,IAAAA,IAAI,EAAE,IAAvD;AAA6DS,IAAAA,QAAQ,EAAE;AAAvE,GAAP,CALsC;AAM9CC,EAAAA,MAAM,EAAE,iCAAO;AAAEtB,IAAAA,KAAK,EAAE,EAAT;AAAaqB,IAAAA,QAAQ,EAAE;AAAvB,GAAP;AANsC,CAAX,GAAhC","sourcesContent":["import { validation } from \"@webiny/validation\";\nimport flow from \"lodash/flow\";\n/**\n * Package commodo-fields-object does not have types\n */\n// @ts-ignore\nimport { object } from \"commodo-fields-object\";\n/**\n * Package commodo-fields does not have object.\n */\n// @ts-ignore\nimport { withFields, string, setOnce, onSet, boolean, fields } from \"@commodo/fields\";\nimport idValidation from \"./idValidation\";\n\nconst requiredShortString = validation.create(\"required,maxLength:255\");\nconst shortString = validation.create(\"maxLength:255\");\n\nexport const CreateContentModelModel = withFields({\n name: string({ validation: requiredShortString }),\n modelId: string({ validation: shortString }),\n description: string({ validation: shortString }),\n group: string({ validation: requiredShortString })\n})();\n\nexport const CreateContentModelModelFrom = withFields({\n name: string({ validation: requiredShortString }),\n modelId: string({ validation: shortString }),\n description: string({ validation: shortString }),\n group: string({ validation: requiredShortString }),\n locale: string({ validation: shortString })\n})();\n\nconst RendererModel = withFields({\n name: string({ validation: requiredShortString })\n})();\n\nexport const ContentModelFieldModel = withFields({\n id: string({ validation: requiredShortString }),\n fieldId: flow(\n onSet((value?: string) => value && value.trim()),\n setOnce()\n )(string({ validation: idValidation })),\n label: string({ validation: requiredShortString }),\n helpText: string({ validation: shortString }),\n placeholderText: string({ validation: shortString }),\n type: setOnce()(string({ validation: requiredShortString })),\n multipleValues: boolean({ value: false }),\n predefinedValues: fields({\n value: {},\n instanceOf: withFields({\n enabled: boolean(),\n values: fields({\n value: [],\n list: true,\n instanceOf: withFields({\n label: string(),\n value: string(),\n selected: boolean()\n })()\n })\n })()\n }),\n renderer: fields({ instanceOf: RendererModel, validation: shortString }),\n validation: fields({\n list: true,\n value: [],\n instanceOf: withFields({\n name: string({ validation: requiredShortString }),\n message: string({ validation: shortString }),\n settings: object({ value: {} })\n })()\n }),\n listValidation: fields({\n list: true,\n value: [],\n instanceOf: withFields({\n name: string({ validation: requiredShortString }),\n message: string({ validation: shortString }),\n settings: object({ value: {} })\n })()\n }),\n settings: object({ value: {} })\n})();\n\nexport const UpdateContentModelModel = withFields({\n name: string({ validation: shortString }),\n description: string({ validation: shortString }),\n group: string({ validation: shortString }),\n titleFieldId: string(),\n fields: fields({ instanceOf: ContentModelFieldModel, value: [], list: true, required: true }),\n layout: object({ value: [], required: true })\n})();\n"]}
1
+ {"version":3,"names":["requiredShortString","validation","create","shortString","RendererModel","withFields","name","string","ContentModelFieldModel","id","fieldId","flow","onSet","value","trim","setOnce","idValidation","label","helpText","placeholderText","type","multipleValues","boolean","predefinedValues","fields","instanceOf","enabled","values","list","selected","renderer","message","settings","object","listValidation","CreateContentModelModel","modelId","description","group","required","layout","CreateContentModelModelFrom","locale","UpdateContentModelModel","titleFieldId"],"sources":["models.ts"],"sourcesContent":["import { validation } from \"@webiny/validation\";\nimport flow from \"lodash/flow\";\n/**\n * Package commodo-fields-object does not have types\n */\n// @ts-ignore\nimport { object } from \"commodo-fields-object\";\n/**\n * Package commodo-fields does not have object.\n */\n// @ts-ignore\nimport { withFields, string, setOnce, onSet, boolean, fields } from \"@commodo/fields\";\nimport idValidation from \"./idValidation\";\n\nconst requiredShortString = validation.create(\"required,maxLength:255\");\nconst shortString = validation.create(\"maxLength:255\");\n\nconst RendererModel = withFields({\n name: string({ validation: requiredShortString })\n})();\n\nexport const ContentModelFieldModel = withFields({\n id: string({ validation: requiredShortString }),\n fieldId: flow(\n onSet((value?: string) => value && value.trim()),\n setOnce()\n )(string({ validation: idValidation })),\n label: string({ validation: requiredShortString }),\n helpText: string({ validation: shortString }),\n placeholderText: string({ validation: shortString }),\n type: setOnce()(string({ validation: requiredShortString })),\n multipleValues: boolean({ value: false }),\n predefinedValues: fields({\n value: {},\n instanceOf: withFields({\n enabled: boolean(),\n values: fields({\n value: [],\n list: true,\n instanceOf: withFields({\n label: string(),\n value: string(),\n selected: boolean()\n })()\n })\n })()\n }),\n renderer: fields({ instanceOf: RendererModel, validation: shortString }),\n validation: fields({\n list: true,\n value: [],\n instanceOf: withFields({\n name: string({ validation: requiredShortString }),\n message: string({ validation: shortString }),\n settings: object({ value: {} })\n })()\n }),\n listValidation: fields({\n list: true,\n value: [],\n instanceOf: withFields({\n name: string({ validation: requiredShortString }),\n message: string({ validation: shortString }),\n settings: object({ value: {} })\n })()\n }),\n settings: object({ value: {} })\n})();\n\nexport const CreateContentModelModel = withFields({\n name: string({ validation: requiredShortString }),\n modelId: string({ validation: shortString }),\n description: string({ validation: shortString }),\n group: string({ validation: requiredShortString }),\n fields: fields({ instanceOf: ContentModelFieldModel, value: [], list: true, required: true }),\n layout: object({ value: [], required: true })\n})();\n\nexport const CreateContentModelModelFrom = withFields({\n name: string({ validation: requiredShortString }),\n modelId: string({ validation: shortString }),\n description: string({ validation: shortString }),\n group: string({ validation: requiredShortString }),\n locale: string({ validation: shortString })\n})();\n\nexport const UpdateContentModelModel = withFields({\n name: string({ validation: shortString }),\n description: string({ validation: shortString }),\n group: string({ validation: shortString }),\n titleFieldId: string(),\n fields: fields({ instanceOf: ContentModelFieldModel, value: [], list: true, required: true }),\n layout: object({ value: [], required: true })\n})();\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AAKA;;AAKA;;AACA;;AAVA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AAIA,MAAMA,mBAAmB,GAAGC,sBAAA,CAAWC,MAAX,CAAkB,wBAAlB,CAA5B;;AACA,MAAMC,WAAW,GAAGF,sBAAA,CAAWC,MAAX,CAAkB,eAAlB,CAApB;;AAEA,MAAME,aAAa,GAAG,IAAAC,kBAAA,EAAW;EAC7BC,IAAI,EAAE,IAAAC,cAAA,EAAO;IAAEN,UAAU,EAAED;EAAd,CAAP;AADuB,CAAX,GAAtB;AAIO,MAAMQ,sBAAsB,GAAG,IAAAH,kBAAA,EAAW;EAC7CI,EAAE,EAAE,IAAAF,cAAA,EAAO;IAAEN,UAAU,EAAED;EAAd,CAAP,CADyC;EAE7CU,OAAO,EAAE,IAAAC,aAAA,EACL,IAAAC,aAAA,EAAOC,KAAD,IAAoBA,KAAK,IAAIA,KAAK,CAACC,IAAN,EAAnC,CADK,EAEL,IAAAC,eAAA,GAFK,EAGP,IAAAR,cAAA,EAAO;IAAEN,UAAU,EAAEe;EAAd,CAAP,CAHO,CAFoC;EAM7CC,KAAK,EAAE,IAAAV,cAAA,EAAO;IAAEN,UAAU,EAAED;EAAd,CAAP,CANsC;EAO7CkB,QAAQ,EAAE,IAAAX,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP,CAPmC;EAQ7CgB,eAAe,EAAE,IAAAZ,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP,CAR4B;EAS7CiB,IAAI,EAAE,IAAAL,eAAA,IAAU,IAAAR,cAAA,EAAO;IAAEN,UAAU,EAAED;EAAd,CAAP,CAAV,CATuC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CAHqC;EAIlDmC,KAAK,EAAE,IAAA/B,cAAA,EAAO;IAAEN,UAAU,EAAED;EAAd,CAAP,CAJ2C;EAKlD0C,MAAM,EAAE,IAAAnC,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP;AAL0C,CAAX,GAApC;;AAQA,MAAMwC,uBAAuB,GAAG,IAAAtC,kBAAA,EAAW;EAC9CC,IAAI,EAAE,IAAAC,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP,CADwC;EAE9CkC,WAAW,EAAE,IAAA9B,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP,CAFiC;EAG9CmC,KAAK,EAAE,IAAA/B,cAAA,EAAO;IAAEN,UAAU,EAAEE;EAAd,CAAP,CAHuC;EAI9CyC,YAAY,EAAE,IAAArC,cAAA,GAJgC;EAK9CiB,MAAM,EAAE,IAAAA,cAAA,EAAO;IAAEC,UAAU,EAAEjB,sBAAd;IAAsCK,KAAK,EAAE,EAA7C;IAAiDe,IAAI,EAAE,IAAvD;IAA6DW,QAAQ,EAAE;EAAvE,CAAP,CALsC;EAM9CC,MAAM,EAAE,IAAAP,2BAAA,EAAO;IAAEpB,KAAK,EAAE,EAAT;IAAa0B,QAAQ,EAAE;EAAvB,CAAP;AANsC,CAAX,GAAhC"}
@@ -1,2 +1,2 @@
1
1
  import { CmsModelField, CmsModel } from "../../../../types";
2
- export declare const validateLayout: ({ layout }: CmsModel, fields: CmsModelField[]) => void;
2
+ export declare const validateLayout: (model: CmsModel, fields?: CmsModelField[]) => void;
@@ -5,9 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.validateLayout = void 0;
7
7
 
8
- const validateLayout = ({
9
- layout
10
- }, fields) => {
8
+ const validateLayout = (model, fields = []) => {
9
+ const layout = model.layout || [];
11
10
  const flatLayoutIdList = layout.reduce((acc, id) => {
12
11
  return acc.concat(Array.isArray(id) ? id : [id]);
13
12
  }, []);
@@ -1 +1 @@
1
- {"version":3,"sources":["validateLayout.ts"],"names":["validateLayout","layout","fields","flatLayoutIdList","reduce","acc","id","concat","Array","isArray","length","Error","field","includes","fieldFound","some","f"],"mappings":";;;;;;;AAEO,MAAMA,cAAc,GAAG,CAAC;AAAEC,EAAAA;AAAF,CAAD,EAAuBC,MAAvB,KAAyD;AACnF,QAAMC,gBAAgB,GAAGF,MAAM,CAACG,MAAP,CAAc,CAACC,GAAD,EAAMC,EAAN,KAAa;AAChD,WAAOD,GAAG,CAACE,MAAJ,CAAWC,KAAK,CAACC,OAAN,CAAcH,EAAd,IAAoBA,EAApB,GAAyB,CAACA,EAAD,CAApC,CAAP;AACH,GAFwB,EAEtB,EAFsB,CAAzB;;AAGA,MAAIH,gBAAgB,CAACO,MAAjB,KAA4BR,MAAM,CAACQ,MAAvC,EAA+C;AAC3C,UAAM,IAAIC,KAAJ,CACD,aAAYR,gBAAgB,CAACO,MAAO,0BAAyBR,MAAM,CAACQ,MAAO,yDAD1E,CAAN;AAGH;;AACD,OAAK,MAAME,KAAX,IAAoBV,MAApB,EAA4B;AACxB,QAAIC,gBAAgB,CAACU,QAAjB,CAA0BD,KAAK,CAACN,EAAhC,CAAJ,EAAyC;AACrC;AACH;;AACD,UAAM,IAAIK,KAAJ,CAAW,UAASC,KAAK,CAACN,EAAG,6BAA7B,CAAN;AACH;;AACD,OAAK,MAAMA,EAAX,IAAiBH,gBAAjB,EAAmC;AAC/B,UAAMW,UAAU,GAAGZ,MAAM,CAACa,IAAP,CAAYC,CAAC,IAAIA,CAAC,CAACV,EAAF,KAASA,EAA1B,CAAnB;;AACA,QAAIQ,UAAJ,EAAgB;AACZ;AACH;;AACD,UAAM,IAAIH,KAAJ,CAAW,aAAYL,EAAG,mCAA1B,CAAN;AACH;AACJ,CAtBM","sourcesContent":["import { CmsModelField, CmsModel } from \"~/types\";\n\nexport const validateLayout = ({ layout }: CmsModel, 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"]}
1
+ {"version":3,"names":["validateLayout","model","fields","layout","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 = (model: CmsModel, fields: CmsModelField[] = []): void => {\n const layout = model.layout || [];\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,KAAD,EAAkBC,MAAuB,GAAG,EAA5C,KAAyD;EACnF,MAAMC,MAAM,GAAGF,KAAK,CAACE,MAAN,IAAgB,EAA/B;EACA,MAAMC,gBAAgB,GAAGD,MAAM,CAACE,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,KAA4BT,MAAM,CAACS,MAAvC,EAA+C;IAC3C,MAAM,IAAIC,KAAJ,CACD,aAAYR,gBAAgB,CAACO,MAAO,0BAAyBT,MAAM,CAACS,MAAO,yDAD1E,CAAN;EAGH;;EACD,KAAK,MAAME,KAAX,IAAoBX,MAApB,EAA4B;IACxB,IAAIE,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,GAAGb,MAAM,CAACc,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,CAvBM"}
@@ -0,0 +1,8 @@
1
+ import { CmsModel } from "../../../../types";
2
+ import { PluginsContainer } from "@webiny/plugins";
3
+ interface ValidateModelParams {
4
+ model: CmsModel;
5
+ plugins: PluginsContainer;
6
+ }
7
+ export declare const validateModelFields: (params: ValidateModelParams) => Promise<void>;
8
+ export {};