@webiny/api-headless-cms 0.0.0-unstable.7f63ea0744 → 0.0.0-unstable.8acc9e8892

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 (184) hide show
  1. package/context.js +47 -43
  2. package/context.js.map +1 -1
  3. package/crud/contentEntry/markLockedFields.d.ts +1 -1
  4. package/crud/contentEntry/markLockedFields.js +13 -2
  5. package/crud/contentEntry/markLockedFields.js.map +1 -1
  6. package/crud/contentEntry/referenceFieldsMapping.js +34 -5
  7. package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
  8. package/crud/contentEntry.crud.d.ts +5 -2
  9. package/crud/contentEntry.crud.js +848 -830
  10. package/crud/contentEntry.crud.js.map +1 -1
  11. package/crud/contentModel/beforeCreate.js +39 -76
  12. package/crud/contentModel/beforeCreate.js.map +1 -1
  13. package/crud/contentModel/beforeDelete.d.ts +1 -1
  14. package/crud/contentModel/beforeDelete.js +1 -5
  15. package/crud/contentModel/beforeDelete.js.map +1 -1
  16. package/crud/contentModel/beforeUpdate.js +31 -3
  17. package/crud/contentModel/beforeUpdate.js.map +1 -1
  18. package/crud/contentModel/compatibility/modelApiName.d.ts +3 -0
  19. package/crud/contentModel/compatibility/modelApiName.js +24 -0
  20. package/crud/contentModel/compatibility/modelApiName.js.map +1 -0
  21. package/crud/contentModel/createFieldModels.d.ts +2 -0
  22. package/crud/contentModel/createFieldModels.js +26 -0
  23. package/crud/contentModel/createFieldModels.js.map +1 -0
  24. package/crud/contentModel/defaultFields.d.ts +5 -0
  25. package/crud/contentModel/defaultFields.js +58 -0
  26. package/crud/contentModel/defaultFields.js.map +1 -0
  27. package/crud/contentModel/fieldIdValidation.d.ts +1 -0
  28. package/crud/contentModel/fieldIdValidation.js +25 -0
  29. package/crud/contentModel/fieldIdValidation.js.map +1 -0
  30. package/crud/contentModel/fields/descriptionField.d.ts +2 -0
  31. package/crud/contentModel/fields/descriptionField.js +42 -0
  32. package/crud/contentModel/fields/descriptionField.js.map +1 -0
  33. package/crud/contentModel/fields/imageField.d.ts +2 -0
  34. package/crud/contentModel/fields/imageField.js +46 -0
  35. package/crud/contentModel/fields/imageField.js.map +1 -0
  36. package/crud/contentModel/fields/titleField.d.ts +2 -0
  37. package/crud/contentModel/fields/titleField.js +58 -0
  38. package/crud/contentModel/fields/titleField.js.map +1 -0
  39. package/crud/contentModel/idValidation.d.ts +1 -0
  40. package/crud/contentModel/idValidation.js +22 -0
  41. package/crud/contentModel/idValidation.js.map +1 -0
  42. package/crud/contentModel/models.d.ts +4 -0
  43. package/crud/contentModel/models.js +192 -0
  44. package/crud/contentModel/models.js.map +1 -0
  45. package/crud/contentModel/systemFields.js.map +1 -1
  46. package/crud/contentModel/validate/endingAllowed.d.ts +6 -0
  47. package/crud/contentModel/validate/endingAllowed.js +26 -0
  48. package/crud/contentModel/validate/endingAllowed.js.map +1 -0
  49. package/crud/contentModel/validate/isModelEndingAllowed.d.ts +6 -0
  50. package/crud/contentModel/validate/isModelEndingAllowed.js +24 -0
  51. package/crud/contentModel/validate/isModelEndingAllowed.js.map +1 -0
  52. package/crud/contentModel/validate/modelId.d.ts +11 -0
  53. package/crud/contentModel/validate/modelId.js +36 -0
  54. package/crud/contentModel/validate/modelId.js.map +1 -0
  55. package/crud/contentModel/validate/pluralApiName.d.ts +7 -0
  56. package/crud/contentModel/validate/pluralApiName.js +24 -0
  57. package/crud/contentModel/validate/pluralApiName.js.map +1 -0
  58. package/crud/contentModel/validate/singularApiName.d.ts +7 -0
  59. package/crud/contentModel/validate/singularApiName.js +24 -0
  60. package/crud/contentModel/validate/singularApiName.js.map +1 -0
  61. package/crud/contentModel/validateModel.d.ts +1 -0
  62. package/crud/contentModel/validateModel.js.map +1 -1
  63. package/crud/contentModel/validateModelFields.d.ts +2 -1
  64. package/crud/contentModel/validateModelFields.js +29 -56
  65. package/crud/contentModel/validateModelFields.js.map +1 -1
  66. package/crud/contentModel/validation.d.ts +195 -121
  67. package/crud/contentModel/validation.js +61 -13
  68. package/crud/contentModel/validation.js.map +1 -1
  69. package/crud/contentModel.crud.js +346 -285
  70. package/crud/contentModel.crud.js.map +1 -1
  71. package/crud/contentModelGroup/validation.d.ts +4 -4
  72. package/crud/contentModelGroup.crud.js +170 -142
  73. package/crud/contentModelGroup.crud.js.map +1 -1
  74. package/crud/settings.crud.d.ts +1 -1
  75. package/crud/settings.crud.js +5 -10
  76. package/crud/settings.crud.js.map +1 -1
  77. package/crud/system.crud.js +0 -60
  78. package/crud/system.crud.js.map +1 -1
  79. package/graphql/checkEndpointAccess.d.ts +2 -0
  80. package/graphql/checkEndpointAccess.js +18 -0
  81. package/graphql/checkEndpointAccess.js.map +1 -0
  82. package/graphql/createExecutableSchema.d.ts +2 -3
  83. package/graphql/createExecutableSchema.js.map +1 -1
  84. package/graphql/createRequestBody.d.ts +2 -0
  85. package/graphql/createRequestBody.js +14 -0
  86. package/graphql/createRequestBody.js.map +1 -0
  87. package/graphql/formatErrorPayload.d.ts +1 -0
  88. package/graphql/formatErrorPayload.js +25 -0
  89. package/graphql/formatErrorPayload.js.map +1 -0
  90. package/graphql/generateSchema.js.map +1 -1
  91. package/graphql/getSchema.d.ts +17 -0
  92. package/graphql/getSchema.js +102 -0
  93. package/graphql/getSchema.js.map +1 -0
  94. package/graphql/graphQLHandlerFactory.js +6 -145
  95. package/graphql/graphQLHandlerFactory.js.map +1 -1
  96. package/graphql/handleRequest.d.ts +11 -0
  97. package/graphql/handleRequest.js +81 -0
  98. package/graphql/handleRequest.js.map +1 -0
  99. package/graphql/index.d.ts +1 -1
  100. package/graphql/schema/baseContentSchema.js +4 -8
  101. package/graphql/schema/baseContentSchema.js.map +1 -1
  102. package/graphql/schema/contentEntries.js +90 -53
  103. package/graphql/schema/contentEntries.js.map +1 -1
  104. package/graphql/schema/contentModelGroups.js +7 -7
  105. package/graphql/schema/contentModelGroups.js.map +1 -1
  106. package/graphql/schema/contentModels.js +23 -4
  107. package/graphql/schema/contentModels.js.map +1 -1
  108. package/graphql/schema/createFieldResolvers.js +2 -1
  109. package/graphql/schema/createFieldResolvers.js.map +1 -1
  110. package/graphql/schema/createManageResolvers.d.ts +1 -1
  111. package/graphql/schema/createManageResolvers.js +33 -17
  112. package/graphql/schema/createManageResolvers.js.map +1 -1
  113. package/graphql/schema/createManageSDL.d.ts +1 -0
  114. package/graphql/schema/createManageSDL.js +55 -49
  115. package/graphql/schema/createManageSDL.js.map +1 -1
  116. package/graphql/schema/createPreviewResolvers.js +3 -7
  117. package/graphql/schema/createPreviewResolvers.js.map +1 -1
  118. package/graphql/schema/createReadResolvers.js +4 -8
  119. package/graphql/schema/createReadResolvers.js.map +1 -1
  120. package/graphql/schema/createReadSDL.d.ts +1 -0
  121. package/graphql/schema/createReadSDL.js +24 -22
  122. package/graphql/schema/createReadSDL.js.map +1 -1
  123. package/graphql/schema/resolvers/commonFieldResolvers.d.ts +3 -2
  124. package/graphql/schema/resolvers/commonFieldResolvers.js +2 -1
  125. package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -1
  126. package/graphql/schema/schemaPlugins.js +12 -12
  127. package/graphql/schema/schemaPlugins.js.map +1 -1
  128. package/graphql/system.js +0 -16
  129. package/graphql/system.js.map +1 -1
  130. package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +1 -1
  131. package/graphqlFields/dynamicZone/dynamicZoneField.js +54 -19
  132. package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -1
  133. package/graphqlFields/object.js +21 -2
  134. package/graphqlFields/object.js.map +1 -1
  135. package/graphqlFields/ref.js +42 -14
  136. package/graphqlFields/ref.js.map +1 -1
  137. package/index.d.ts +4 -2
  138. package/index.js +25 -2
  139. package/index.js.map +1 -1
  140. package/package.json +22 -23
  141. package/plugins/CmsModelPlugin.d.ts +21 -3
  142. package/plugins/CmsModelPlugin.js +28 -2
  143. package/plugins/CmsModelPlugin.js.map +1 -1
  144. package/plugins/StorageOperationsCmsModelPlugin.d.ts +23 -0
  145. package/plugins/StorageOperationsCmsModelPlugin.js +42 -0
  146. package/plugins/StorageOperationsCmsModelPlugin.js.map +1 -0
  147. package/plugins/index.d.ts +1 -0
  148. package/plugins/index.js +11 -0
  149. package/plugins/index.js.map +1 -1
  150. package/types.d.ts +121 -67
  151. package/types.js +1 -1
  152. package/types.js.map +1 -1
  153. package/upgrades/5.33.0/index.js +26 -3
  154. package/upgrades/5.33.0/index.js.map +1 -1
  155. package/upgrades/index.js +3 -0
  156. package/upgrades/index.js.map +1 -1
  157. package/utils/converters/valueKeyStorageConverter.d.ts +1 -5
  158. package/utils/converters/valueKeyStorageConverter.js +21 -18
  159. package/utils/converters/valueKeyStorageConverter.js.map +1 -1
  160. package/utils/createTypeFromFields.d.ts +1 -0
  161. package/utils/createTypeFromFields.js +7 -5
  162. package/utils/createTypeFromFields.js.map +1 -1
  163. package/utils/createTypeName.d.ts +0 -2
  164. package/utils/createTypeName.js +2 -10
  165. package/utils/createTypeName.js.map +1 -1
  166. package/utils/getEntryDescription.d.ts +2 -0
  167. package/utils/getEntryDescription.js +17 -0
  168. package/utils/getEntryDescription.js.map +1 -0
  169. package/utils/getEntryImage.d.ts +2 -0
  170. package/utils/getEntryImage.js +17 -0
  171. package/utils/getEntryImage.js.map +1 -0
  172. package/utils/incrementEntryIdVersion.d.ts +5 -0
  173. package/utils/incrementEntryIdVersion.js +29 -0
  174. package/utils/incrementEntryIdVersion.js.map +1 -0
  175. package/utils/ownership.d.ts +3 -3
  176. package/utils/ownership.js.map +1 -1
  177. package/utils/pluralizedTypeName.js +6 -0
  178. package/utils/pluralizedTypeName.js.map +1 -1
  179. package/utils/renderFields.d.ts +2 -1
  180. package/utils/renderFields.js +8 -1
  181. package/utils/renderFields.js.map +1 -1
  182. package/utils/renderInputFields.d.ts +2 -1
  183. package/utils/renderInputFields.js +4 -0
  184. package/utils/renderInputFields.js.map +1 -1
@@ -7,7 +7,6 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.assignModelBeforeDelete = void 0;
8
8
  var _error = _interopRequireDefault(require("@webiny/error"));
9
9
  var _CmsModelPlugin = require("../../plugins/CmsModelPlugin");
10
- var _valueKeyStorageConverter = require("../../utils/converters/valueKeyStorageConverter");
11
10
  const assignModelBeforeDelete = params => {
12
11
  const {
13
12
  onModelBeforeDelete,
@@ -26,10 +25,7 @@ const assignModelBeforeDelete = params => {
26
25
  }
27
26
  let entries = [];
28
27
  try {
29
- const result = await storageOperations.entries.list((0, _valueKeyStorageConverter.attachCmsModelFieldConverters)({
30
- model,
31
- plugins
32
- }), {
28
+ const result = await storageOperations.entries.list(model, {
33
29
  where: {
34
30
  latest: true
35
31
  },
@@ -1 +1 @@
1
- {"version":3,"names":["assignModelBeforeDelete","params","onModelBeforeDelete","storageOperations","plugins","subscribe","model","modelPlugin","byType","CmsModelPlugin","type","find","item","contentModel","modelId","WebinyError","entries","result","list","attachCmsModelFieldConverters","where","latest","limit","items","ex","error","length"],"sources":["beforeDelete.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { OnModelBeforeDeleteTopicParams, HeadlessCmsStorageOperations } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport WebinyError from \"@webiny/error\";\nimport { CmsModelPlugin } from \"~/plugins/CmsModelPlugin\";\nimport { attachCmsModelFieldConverters } from \"~/utils/converters/valueKeyStorageConverter\";\n\ninterface AssignBeforeModelDeleteParams {\n onModelBeforeDelete: Topic<OnModelBeforeDeleteTopicParams>;\n storageOperations: HeadlessCmsStorageOperations;\n plugins: PluginsContainer;\n}\nexport const assignModelBeforeDelete = (params: AssignBeforeModelDeleteParams) => {\n const { onModelBeforeDelete, storageOperations, plugins } = params;\n\n onModelBeforeDelete.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 deleted.\",\n \"CONTENT_MODEL_DELETE_ERROR\",\n {\n modelId: model.modelId\n }\n );\n }\n\n let entries = [];\n try {\n const result = await storageOperations.entries.list(\n attachCmsModelFieldConverters({\n model,\n plugins\n }),\n {\n where: {\n latest: true\n },\n limit: 1\n }\n );\n entries = result.items;\n } catch (ex) {\n throw new WebinyError(\n \"Could not retrieve a list of content entries from the model.\",\n \"ENTRIES_ERROR\",\n {\n error: ex,\n model\n }\n );\n }\n if (entries.length > 0) {\n throw new WebinyError(\n `Cannot delete content model \"${model.modelId}\" because there are existing entries.`,\n \"CONTENT_MODEL_BEFORE_DELETE_HOOK_FAILED\"\n );\n }\n });\n};\n"],"mappings":";;;;;;;AAGA;AACA;AACA;AAOO,MAAMA,uBAAuB,GAAIC,MAAqC,IAAK;EAC9E,MAAM;IAAEC,mBAAmB;IAAEC,iBAAiB;IAAEC;EAAQ,CAAC,GAAGH,MAAM;EAElEC,mBAAmB,CAACG,SAAS,CAAC,MAAMJ,MAAM,IAAI;IAC1C,MAAM;MAAEK;IAAM,CAAC,GAAGL,MAAM;IAExB,MAAMM,WAAW,GAAGH,OAAO,CACtBI,MAAM,CAAiBC,8BAAc,CAACC,IAAI,CAAC,CAC3CC,IAAI,CAACC,IAAI,IAAIA,IAAI,CAACC,YAAY,CAACC,OAAO,KAAKR,KAAK,CAACQ,OAAO,CAAC;IAE9D,IAAIP,WAAW,EAAE;MACb,MAAM,IAAIQ,cAAW,CACjB,uDAAuD,EACvD,4BAA4B,EAC5B;QACID,OAAO,EAAER,KAAK,CAACQ;MACnB,CAAC,CACJ;IACL;IAEA,IAAIE,OAAO,GAAG,EAAE;IAChB,IAAI;MACA,MAAMC,MAAM,GAAG,MAAMd,iBAAiB,CAACa,OAAO,CAACE,IAAI,CAC/C,IAAAC,uDAA6B,EAAC;QAC1Bb,KAAK;QACLF;MACJ,CAAC,CAAC,EACF;QACIgB,KAAK,EAAE;UACHC,MAAM,EAAE;QACZ,CAAC;QACDC,KAAK,EAAE;MACX,CAAC,CACJ;MACDN,OAAO,GAAGC,MAAM,CAACM,KAAK;IAC1B,CAAC,CAAC,OAAOC,EAAE,EAAE;MACT,MAAM,IAAIT,cAAW,CACjB,8DAA8D,EAC9D,eAAe,EACf;QACIU,KAAK,EAAED,EAAE;QACTlB;MACJ,CAAC,CACJ;IACL;IACA,IAAIU,OAAO,CAACU,MAAM,GAAG,CAAC,EAAE;MACpB,MAAM,IAAIX,cAAW,CAChB,gCAA+BT,KAAK,CAACQ,OAAQ,uCAAsC,EACpF,yCAAyC,CAC5C;IACL;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
1
+ {"version":3,"names":["assignModelBeforeDelete","params","onModelBeforeDelete","storageOperations","plugins","subscribe","model","modelPlugin","byType","CmsModelPlugin","type","find","item","contentModel","modelId","WebinyError","entries","result","list","where","latest","limit","items","ex","error","length"],"sources":["beforeDelete.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { HeadlessCmsStorageOperations, OnModelBeforeDeleteTopicParams } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport WebinyError from \"@webiny/error\";\nimport { CmsModelPlugin } from \"~/plugins/CmsModelPlugin\";\n\ninterface AssignBeforeModelDeleteParams {\n onModelBeforeDelete: Topic<OnModelBeforeDeleteTopicParams>;\n storageOperations: HeadlessCmsStorageOperations;\n plugins: PluginsContainer;\n}\nexport const assignModelBeforeDelete = (params: AssignBeforeModelDeleteParams) => {\n const { onModelBeforeDelete, storageOperations, plugins } = params;\n\n onModelBeforeDelete.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 deleted.\",\n \"CONTENT_MODEL_DELETE_ERROR\",\n {\n modelId: model.modelId\n }\n );\n }\n\n let entries = [];\n try {\n const result = await storageOperations.entries.list(model, {\n where: {\n latest: true\n },\n limit: 1\n });\n entries = result.items;\n } catch (ex) {\n throw new WebinyError(\n \"Could not retrieve a list of content entries from the model.\",\n \"ENTRIES_ERROR\",\n {\n error: ex,\n model\n }\n );\n }\n if (entries.length > 0) {\n throw new WebinyError(\n `Cannot delete content model \"${model.modelId}\" because there are existing entries.`,\n \"CONTENT_MODEL_BEFORE_DELETE_HOOK_FAILED\"\n );\n }\n });\n};\n"],"mappings":";;;;;;;AAGA;AACA;AAOO,MAAMA,uBAAuB,GAAIC,MAAqC,IAAK;EAC9E,MAAM;IAAEC,mBAAmB;IAAEC,iBAAiB;IAAEC;EAAQ,CAAC,GAAGH,MAAM;EAElEC,mBAAmB,CAACG,SAAS,CAAC,MAAMJ,MAAM,IAAI;IAC1C,MAAM;MAAEK;IAAM,CAAC,GAAGL,MAAM;IAExB,MAAMM,WAAW,GAAGH,OAAO,CACtBI,MAAM,CAAiBC,8BAAc,CAACC,IAAI,CAAC,CAC3CC,IAAI,CAACC,IAAI,IAAIA,IAAI,CAACC,YAAY,CAACC,OAAO,KAAKR,KAAK,CAACQ,OAAO,CAAC;IAE9D,IAAIP,WAAW,EAAE;MACb,MAAM,IAAIQ,cAAW,CACjB,uDAAuD,EACvD,4BAA4B,EAC5B;QACID,OAAO,EAAER,KAAK,CAACQ;MACnB,CAAC,CACJ;IACL;IAEA,IAAIE,OAAO,GAAG,EAAE;IAChB,IAAI;MACA,MAAMC,MAAM,GAAG,MAAMd,iBAAiB,CAACa,OAAO,CAACE,IAAI,CAACZ,KAAK,EAAE;QACvDa,KAAK,EAAE;UACHC,MAAM,EAAE;QACZ,CAAC;QACDC,KAAK,EAAE;MACX,CAAC,CAAC;MACFL,OAAO,GAAGC,MAAM,CAACK,KAAK;IAC1B,CAAC,CAAC,OAAOC,EAAE,EAAE;MACT,MAAM,IAAIR,cAAW,CACjB,8DAA8D,EAC9D,eAAe,EACf;QACIS,KAAK,EAAED,EAAE;QACTjB;MACJ,CAAC,CACJ;IACL;IACA,IAAIU,OAAO,CAACS,MAAM,GAAG,CAAC,EAAE;MACpB,MAAM,IAAIV,cAAW,CAChB,gCAA+BT,KAAK,CAACQ,OAAQ,uCAAsC,EACpF,yCAAyC,CAC5C;IACL;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -6,24 +6,52 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.assignModelBeforeUpdate = void 0;
7
7
  var _validateModel = require("./validateModel");
8
8
  var _validateLayout = require("./validateLayout");
9
+ var _singularApiName = require("./validate/singularApiName");
10
+ var _pluralApiName = require("./validate/pluralApiName");
11
+ var _endingAllowed = require("./validate/endingAllowed");
9
12
  const assignModelBeforeUpdate = params => {
10
13
  const {
11
14
  onModelBeforeUpdate,
12
15
  context
13
16
  } = params;
14
17
  onModelBeforeUpdate.subscribe(async ({
15
- model,
18
+ model: newModel,
16
19
  original
17
20
  }) => {
18
21
  /**
19
22
  * First we go through the layout...
20
23
  */
21
- (0, _validateLayout.validateLayout)(model.layout, model.fields);
24
+ (0, _validateLayout.validateLayout)(newModel.layout, newModel.fields);
25
+ const models = await context.security.withoutAuthorization(async () => {
26
+ return (await context.cms.listModels()).filter(model => {
27
+ return model.modelId !== newModel.modelId;
28
+ });
29
+ });
30
+ (0, _endingAllowed.validateEndingAllowed)({
31
+ model: newModel
32
+ });
33
+ /**
34
+ * We need to check for the existence of:
35
+ * - modelId
36
+ * - singularApiName
37
+ * - pluralApiName
38
+ */
39
+ for (const model of models) {
40
+ (0, _singularApiName.validateSingularApiName)({
41
+ existingModel: model,
42
+ model: newModel
43
+ });
44
+ (0, _pluralApiName.validatePluralApiName)({
45
+ existingModel: model,
46
+ model: newModel
47
+ });
48
+ }
22
49
  /**
23
50
  * then the model and fields...
24
51
  */
25
52
  await (0, _validateModel.validateModel)({
26
- model,
53
+ models,
54
+ model: newModel,
27
55
  original,
28
56
  context
29
57
  });
@@ -1 +1 @@
1
- {"version":3,"names":["assignModelBeforeUpdate","params","onModelBeforeUpdate","context","subscribe","model","original","validateLayout","layout","fields","validateModel"],"sources":["beforeUpdate.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { OnModelBeforeUpdateTopicParams, CmsContext } from \"~/types\";\nimport { validateModel } from \"./validateModel\";\nimport { validateLayout } from \"./validateLayout\";\n\ninterface AssignBeforeModelUpdateParams {\n onModelBeforeUpdate: Topic<OnModelBeforeUpdateTopicParams>;\n context: CmsContext;\n}\n\nexport const assignModelBeforeUpdate = (params: AssignBeforeModelUpdateParams) => {\n const { onModelBeforeUpdate, context } = params;\n\n onModelBeforeUpdate.subscribe(async ({ model, original }) => {\n /**\n * First we go through the layout...\n */\n validateLayout(model.layout, model.fields);\n /**\n * then the model and fields...\n */\n await validateModel({\n model,\n original,\n context\n });\n });\n};\n"],"mappings":";;;;;;AAEA;AACA;AAOO,MAAMA,uBAAuB,GAAIC,MAAqC,IAAK;EAC9E,MAAM;IAAEC,mBAAmB;IAAEC;EAAQ,CAAC,GAAGF,MAAM;EAE/CC,mBAAmB,CAACE,SAAS,CAAC,OAAO;IAAEC,KAAK;IAAEC;EAAS,CAAC,KAAK;IACzD;AACR;AACA;IACQ,IAAAC,8BAAc,EAACF,KAAK,CAACG,MAAM,EAAEH,KAAK,CAACI,MAAM,CAAC;IAC1C;AACR;AACA;IACQ,MAAM,IAAAC,4BAAa,EAAC;MAChBL,KAAK;MACLC,QAAQ;MACRH;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AAAC"}
1
+ {"version":3,"names":["assignModelBeforeUpdate","params","onModelBeforeUpdate","context","subscribe","model","newModel","original","validateLayout","layout","fields","models","security","withoutAuthorization","cms","listModels","filter","modelId","validateEndingAllowed","validateSingularApiName","existingModel","validatePluralApiName","validateModel"],"sources":["beforeUpdate.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { OnModelBeforeUpdateTopicParams, CmsContext } from \"~/types\";\nimport { validateModel } from \"./validateModel\";\nimport { validateLayout } from \"./validateLayout\";\nimport { validateSingularApiName } from \"./validate/singularApiName\";\nimport { validatePluralApiName } from \"./validate/pluralApiName\";\nimport { validateEndingAllowed } from \"~/crud/contentModel/validate/endingAllowed\";\n\ninterface AssignBeforeModelUpdateParams {\n onModelBeforeUpdate: Topic<OnModelBeforeUpdateTopicParams>;\n context: CmsContext;\n}\n\nexport const assignModelBeforeUpdate = (params: AssignBeforeModelUpdateParams) => {\n const { onModelBeforeUpdate, context } = params;\n\n onModelBeforeUpdate.subscribe(async ({ model: newModel, original }) => {\n /**\n * First we go through the layout...\n */\n validateLayout(newModel.layout, newModel.fields);\n\n const models = await context.security.withoutAuthorization(async () => {\n return (await context.cms.listModels()).filter(model => {\n return model.modelId !== newModel.modelId;\n });\n });\n\n validateEndingAllowed({\n model: newModel\n });\n /**\n * We need to check for the existence of:\n * - modelId\n * - singularApiName\n * - pluralApiName\n */\n for (const model of models) {\n validateSingularApiName({\n existingModel: model,\n model: newModel\n });\n validatePluralApiName({\n existingModel: model,\n model: newModel\n });\n }\n /**\n * then the model and fields...\n */\n await validateModel({\n models,\n model: newModel,\n original,\n context\n });\n });\n};\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACA;AAOO,MAAMA,uBAAuB,GAAIC,MAAqC,IAAK;EAC9E,MAAM;IAAEC,mBAAmB;IAAEC;EAAQ,CAAC,GAAGF,MAAM;EAE/CC,mBAAmB,CAACE,SAAS,CAAC,OAAO;IAAEC,KAAK,EAAEC,QAAQ;IAAEC;EAAS,CAAC,KAAK;IACnE;AACR;AACA;IACQ,IAAAC,8BAAc,EAACF,QAAQ,CAACG,MAAM,EAAEH,QAAQ,CAACI,MAAM,CAAC;IAEhD,MAAMC,MAAM,GAAG,MAAMR,OAAO,CAACS,QAAQ,CAACC,oBAAoB,CAAC,YAAY;MACnE,OAAO,CAAC,MAAMV,OAAO,CAACW,GAAG,CAACC,UAAU,EAAE,EAAEC,MAAM,CAACX,KAAK,IAAI;QACpD,OAAOA,KAAK,CAACY,OAAO,KAAKX,QAAQ,CAACW,OAAO;MAC7C,CAAC,CAAC;IACN,CAAC,CAAC;IAEF,IAAAC,oCAAqB,EAAC;MAClBb,KAAK,EAAEC;IACX,CAAC,CAAC;IACF;AACR;AACA;AACA;AACA;AACA;IACQ,KAAK,MAAMD,KAAK,IAAIM,MAAM,EAAE;MACxB,IAAAQ,wCAAuB,EAAC;QACpBC,aAAa,EAAEf,KAAK;QACpBA,KAAK,EAAEC;MACX,CAAC,CAAC;MACF,IAAAe,oCAAqB,EAAC;QAClBD,aAAa,EAAEf,KAAK;QACpBA,KAAK,EAAEC;MACX,CAAC,CAAC;IACN;IACA;AACR;AACA;IACQ,MAAM,IAAAgB,4BAAa,EAAC;MAChBX,MAAM;MACNN,KAAK,EAAEC,QAAQ;MACfC,QAAQ;MACRJ;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -0,0 +1,3 @@
1
+ import { CmsModel } from "../../../types";
2
+ export declare const ensureSingularApiName: (model: CmsModel) => string;
3
+ export declare const ensurePluralApiName: (model: CmsModel) => string;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.ensureSingularApiName = exports.ensurePluralApiName = void 0;
8
+ var _camelCase = _interopRequireDefault(require("lodash/camelCase"));
9
+ var _upperFirst = _interopRequireDefault(require("lodash/upperFirst"));
10
+ var _pluralize = _interopRequireDefault(require("pluralize"));
11
+ const ensureSingularApiName = model => {
12
+ if (!model.singularApiName) {
13
+ return (0, _upperFirst.default)((0, _camelCase.default)(model.modelId));
14
+ }
15
+ return model.singularApiName;
16
+ };
17
+ exports.ensureSingularApiName = ensureSingularApiName;
18
+ const ensurePluralApiName = model => {
19
+ if (!model.pluralApiName) {
20
+ return (0, _pluralize.default)(ensureSingularApiName(model));
21
+ }
22
+ return model.pluralApiName;
23
+ };
24
+ exports.ensurePluralApiName = ensurePluralApiName;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ensureSingularApiName","model","singularApiName","upperFirst","camelCase","modelId","ensurePluralApiName","pluralApiName","pluralize"],"sources":["modelApiName.ts"],"sourcesContent":["import camelCase from \"lodash/camelCase\";\nimport upperFirst from \"lodash/upperFirst\";\nimport pluralize from \"pluralize\";\nimport { CmsModel } from \"~/types\";\n\nexport const ensureSingularApiName = (model: CmsModel): string => {\n if (!model.singularApiName) {\n return upperFirst(camelCase(model.modelId));\n }\n return model.singularApiName;\n};\n\nexport const ensurePluralApiName = (model: CmsModel): string => {\n if (!model.pluralApiName) {\n return pluralize(ensureSingularApiName(model));\n }\n return model.pluralApiName;\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAGO,MAAMA,qBAAqB,GAAIC,KAAe,IAAa;EAC9D,IAAI,CAACA,KAAK,CAACC,eAAe,EAAE;IACxB,OAAO,IAAAC,mBAAU,EAAC,IAAAC,kBAAS,EAACH,KAAK,CAACI,OAAO,CAAC,CAAC;EAC/C;EACA,OAAOJ,KAAK,CAACC,eAAe;AAChC,CAAC;AAAC;AAEK,MAAMI,mBAAmB,GAAIL,KAAe,IAAa;EAC5D,IAAI,CAACA,KAAK,CAACM,aAAa,EAAE;IACtB,OAAO,IAAAC,kBAAS,EAACR,qBAAqB,CAACC,KAAK,CAAC,CAAC;EAClD;EACA,OAAOA,KAAK,CAACM,aAAa;AAC9B,CAAC;AAAC"}
@@ -0,0 +1,2 @@
1
+ import { CmsModelField, CmsModelFieldInput } from "../../types";
2
+ export declare const createFieldModels: (input?: CmsModelFieldInput[]) => Promise<CmsModelField[]>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createFieldModels = void 0;
7
+
8
+ var _models = require("./models");
9
+
10
+ const createFieldModels = async input => {
11
+ if (!input || input.length === 0) {
12
+ return [];
13
+ }
14
+
15
+ const fields = [];
16
+
17
+ for (const field of input) {
18
+ const fieldData = new _models.ContentModelFieldModel().populate(field);
19
+ await fieldData.validate();
20
+ fields.push(await fieldData.toJSON());
21
+ }
22
+
23
+ return fields;
24
+ };
25
+
26
+ exports.createFieldModels = createFieldModels;
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,5 @@
1
+ import { CmsModelCreateInput } from "../../types";
2
+ /**
3
+ * We only assign default fields if there are no fields in the model already.
4
+ */
5
+ export declare const assignModelDefaultFields: (model: CmsModelCreateInput) => void;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.assignModelDefaultFields = void 0;
7
+ var _utils = require("@webiny/utils");
8
+ const createDefaultFields = () => {
9
+ return [{
10
+ id: (0, _utils.generateAlphaNumericLowerCaseId)(8),
11
+ fieldId: "title",
12
+ type: "text",
13
+ label: "Title",
14
+ validation: [{
15
+ name: "required",
16
+ message: "Title is a required field."
17
+ }],
18
+ listValidation: [],
19
+ renderer: {
20
+ name: "text-input"
21
+ }
22
+ }, {
23
+ id: (0, _utils.generateAlphaNumericLowerCaseId)(8),
24
+ fieldId: "description",
25
+ type: "long-text",
26
+ label: "Description",
27
+ validation: [],
28
+ listValidation: [],
29
+ renderer: {
30
+ name: "long-text-text-area"
31
+ }
32
+ }, {
33
+ id: (0, _utils.generateAlphaNumericLowerCaseId)(8),
34
+ fieldId: "image",
35
+ type: "file",
36
+ label: "Image",
37
+ validation: [],
38
+ listValidation: [],
39
+ renderer: {
40
+ name: "file-input"
41
+ },
42
+ settings: {
43
+ imagesOnly: true
44
+ }
45
+ }];
46
+ };
47
+
48
+ /**
49
+ * We only assign default fields if there are no fields in the model already.
50
+ */
51
+ const assignModelDefaultFields = model => {
52
+ if (model.fields && model.fields.length !== 0) {
53
+ return;
54
+ }
55
+ model.fields = createDefaultFields();
56
+ model.layout = [[model.fields[0].id], [model.fields[1].id, model.fields[2].id]];
57
+ };
58
+ exports.assignModelDefaultFields = assignModelDefaultFields;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createDefaultFields","id","generateAlphaNumericLowerCaseId","fieldId","type","label","validation","name","message","listValidation","renderer","settings","imagesOnly","assignModelDefaultFields","model","fields","length","layout"],"sources":["defaultFields.ts"],"sourcesContent":["import { CmsModelCreateInput, CmsModelFieldInput } from \"~/types\";\nimport { generateAlphaNumericLowerCaseId } from \"@webiny/utils\";\n\nconst createDefaultFields = (): CmsModelFieldInput[] => {\n return [\n {\n id: generateAlphaNumericLowerCaseId(8),\n fieldId: \"title\",\n type: \"text\",\n label: \"Title\",\n validation: [\n {\n name: \"required\",\n message: \"Title is a required field.\"\n }\n ],\n listValidation: [],\n renderer: {\n name: \"text-input\"\n }\n },\n {\n id: generateAlphaNumericLowerCaseId(8),\n fieldId: \"description\",\n type: \"long-text\",\n label: \"Description\",\n validation: [],\n listValidation: [],\n renderer: {\n name: \"long-text-text-area\"\n }\n },\n {\n id: generateAlphaNumericLowerCaseId(8),\n fieldId: \"image\",\n type: \"file\",\n label: \"Image\",\n validation: [],\n listValidation: [],\n renderer: {\n name: \"file-input\"\n },\n settings: {\n imagesOnly: true\n }\n }\n ];\n};\n\n/**\n * We only assign default fields if there are no fields in the model already.\n */\nexport const assignModelDefaultFields = (model: CmsModelCreateInput): void => {\n if (model.fields && model.fields.length !== 0) {\n return;\n }\n\n model.fields = createDefaultFields();\n model.layout = [[model.fields[0].id], [model.fields[1].id, model.fields[2].id]];\n};\n"],"mappings":";;;;;;AACA;AAEA,MAAMA,mBAAmB,GAAG,MAA4B;EACpD,OAAO,CACH;IACIC,EAAE,EAAE,IAAAC,sCAA+B,EAAC,CAAC,CAAC;IACtCC,OAAO,EAAE,OAAO;IAChBC,IAAI,EAAE,MAAM;IACZC,KAAK,EAAE,OAAO;IACdC,UAAU,EAAE,CACR;MACIC,IAAI,EAAE,UAAU;MAChBC,OAAO,EAAE;IACb,CAAC,CACJ;IACDC,cAAc,EAAE,EAAE;IAClBC,QAAQ,EAAE;MACNH,IAAI,EAAE;IACV;EACJ,CAAC,EACD;IACIN,EAAE,EAAE,IAAAC,sCAA+B,EAAC,CAAC,CAAC;IACtCC,OAAO,EAAE,aAAa;IACtBC,IAAI,EAAE,WAAW;IACjBC,KAAK,EAAE,aAAa;IACpBC,UAAU,EAAE,EAAE;IACdG,cAAc,EAAE,EAAE;IAClBC,QAAQ,EAAE;MACNH,IAAI,EAAE;IACV;EACJ,CAAC,EACD;IACIN,EAAE,EAAE,IAAAC,sCAA+B,EAAC,CAAC,CAAC;IACtCC,OAAO,EAAE,OAAO;IAChBC,IAAI,EAAE,MAAM;IACZC,KAAK,EAAE,OAAO;IACdC,UAAU,EAAE,EAAE;IACdG,cAAc,EAAE,EAAE;IAClBC,QAAQ,EAAE;MACNH,IAAI,EAAE;IACV,CAAC;IACDI,QAAQ,EAAE;MACNC,UAAU,EAAE;IAChB;EACJ,CAAC,CACJ;AACL,CAAC;;AAED;AACA;AACA;AACO,MAAMC,wBAAwB,GAAIC,KAA0B,IAAW;EAC1E,IAAIA,KAAK,CAACC,MAAM,IAAID,KAAK,CAACC,MAAM,CAACC,MAAM,KAAK,CAAC,EAAE;IAC3C;EACJ;EAEAF,KAAK,CAACC,MAAM,GAAGf,mBAAmB,EAAE;EACpCc,KAAK,CAACG,MAAM,GAAG,CAAC,CAACH,KAAK,CAACC,MAAM,CAAC,CAAC,CAAC,CAACd,EAAE,CAAC,EAAE,CAACa,KAAK,CAACC,MAAM,CAAC,CAAC,CAAC,CAACd,EAAE,EAAEa,KAAK,CAACC,MAAM,CAAC,CAAC,CAAC,CAACd,EAAE,CAAC,CAAC;AACnF,CAAC;AAAC"}
@@ -0,0 +1 @@
1
+ export declare const validateFieldId: (input: string) => Promise<void>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.validateFieldId = void 0;
7
+
8
+ var _validation = require("@webiny/validation");
9
+
10
+ var _systemFields = require("./systemFields");
11
+
12
+ const validateFieldId = async input => {
13
+ await _validation.validation.validate(input, "required,maxLength:100");
14
+ const value = String(input || "").trim();
15
+
16
+ if (!value.charAt(0).match(/^[a-zA-Z]/)) {
17
+ throw new Error(`Provided ${value} is not valid - must not start with a number.`);
18
+ } else if (value.match(/^([a-zA-Z0-9]+)$/) === null) {
19
+ throw new Error(`Provided ${value} is not valid - must be alphanumeric string.`);
20
+ } else if (_systemFields.fieldSystemFields.includes(value)) {
21
+ throw new Error(`Provided ${value} is not valid - "${value}" is an auto-generated field.`);
22
+ }
23
+ };
24
+
25
+ exports.validateFieldId = validateFieldId;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["validateFieldId","input","validation","validate","value","String","trim","charAt","match","Error","fieldSystemFields","includes"],"sources":["fieldIdValidation.ts"],"sourcesContent":["import { validation } from \"@webiny/validation\";\nimport { fieldSystemFields } from \"~/crud/contentModel/systemFields\";\n\nexport const validateFieldId = async (input: string): Promise<void> => {\n await validation.validate(input, \"required,maxLength:100\");\n\n const value = String(input || \"\").trim();\n\n if (!value.charAt(0).match(/^[a-zA-Z]/)) {\n throw new Error(`Provided ${value} is not valid - must not start with a number.`);\n } else if (value.match(/^([a-zA-Z0-9]+)$/) === null) {\n throw new Error(`Provided ${value} is not valid - must be alphanumeric string.`);\n } else if (fieldSystemFields.includes(value)) {\n throw new Error(`Provided ${value} is not valid - \"${value}\" is an auto-generated field.`);\n }\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AAEO,MAAMA,eAAe,GAAG,MAAOC,KAAP,IAAwC;EACnE,MAAMC,sBAAA,CAAWC,QAAX,CAAoBF,KAApB,EAA2B,wBAA3B,CAAN;EAEA,MAAMG,KAAK,GAAGC,MAAM,CAACJ,KAAK,IAAI,EAAV,CAAN,CAAoBK,IAApB,EAAd;;EAEA,IAAI,CAACF,KAAK,CAACG,MAAN,CAAa,CAAb,EAAgBC,KAAhB,CAAsB,WAAtB,CAAL,EAAyC;IACrC,MAAM,IAAIC,KAAJ,CAAW,YAAWL,KAAM,+CAA5B,CAAN;EACH,CAFD,MAEO,IAAIA,KAAK,CAACI,KAAN,CAAY,kBAAZ,MAAoC,IAAxC,EAA8C;IACjD,MAAM,IAAIC,KAAJ,CAAW,YAAWL,KAAM,8CAA5B,CAAN;EACH,CAFM,MAEA,IAAIM,+BAAA,CAAkBC,QAAlB,CAA2BP,KAA3B,CAAJ,EAAuC;IAC1C,MAAM,IAAIK,KAAJ,CAAW,YAAWL,KAAM,oBAAmBA,KAAM,+BAArD,CAAN;EACH;AACJ,CAZM"}
@@ -0,0 +1,2 @@
1
+ import { CmsModelField } from "../../../types";
2
+ export declare const getContentModelDescriptionFieldId: (fields: CmsModelField[], descriptionFieldId?: string | null) => string | null | undefined;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getContentModelDescriptionFieldId = void 0;
8
+ var _getBaseFieldType = require("../../../utils/getBaseFieldType");
9
+ var _error = _interopRequireDefault(require("@webiny/error"));
10
+ const getContentModelDescriptionFieldId = (fields, descriptionFieldId) => {
11
+ /**
12
+ * If there are no fields defined, we will just set as null.
13
+ */
14
+ if (fields.length === 0) {
15
+ return null;
16
+ }
17
+ /**
18
+ * If description field is not defined, let us find possible one.
19
+ */
20
+ if (!descriptionFieldId) {
21
+ const descriptionField = fields.find(field => {
22
+ return (0, _getBaseFieldType.getBaseFieldType)(field) === "long-text" && !field.multipleValues;
23
+ });
24
+ return (descriptionField === null || descriptionField === void 0 ? void 0 : descriptionField.fieldId) || null;
25
+ }
26
+ const target = fields.find(field => field.fieldId === descriptionFieldId && (0, _getBaseFieldType.getBaseFieldType)(field) === "long-text");
27
+ if (!target) {
28
+ throw new _error.default(`Field selected for the description field does not exist in the model.`, "VALIDATION_ERROR", {
29
+ fieldId: descriptionFieldId,
30
+ fields
31
+ });
32
+ }
33
+ if (target.multipleValues) {
34
+ throw new _error.default(`Fields that accept multiple values cannot be used as the entry description.`, "ENTRY_TITLE_FIELD_TYPE", {
35
+ storageId: target.storageId,
36
+ fieldId: target.fieldId,
37
+ type: target.type
38
+ });
39
+ }
40
+ return target.fieldId;
41
+ };
42
+ exports.getContentModelDescriptionFieldId = getContentModelDescriptionFieldId;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getContentModelDescriptionFieldId","fields","descriptionFieldId","length","descriptionField","find","field","getBaseFieldType","multipleValues","fieldId","target","WebinyError","storageId","type"],"sources":["descriptionField.ts"],"sourcesContent":["import { CmsModelField } from \"~/types\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\nimport WebinyError from \"@webiny/error\";\n\nexport const getContentModelDescriptionFieldId = (\n fields: CmsModelField[],\n descriptionFieldId?: string | null\n): string | null | undefined => {\n /**\n * If there are no fields defined, we will just set as null.\n */\n if (fields.length === 0) {\n return null;\n }\n /**\n * If description field is not defined, let us find possible one.\n */\n if (!descriptionFieldId) {\n const descriptionField = fields.find(field => {\n return getBaseFieldType(field) === \"long-text\" && !field.multipleValues;\n });\n return descriptionField?.fieldId || null;\n }\n const target = fields.find(\n field => field.fieldId === descriptionFieldId && getBaseFieldType(field) === \"long-text\"\n );\n if (!target) {\n throw new WebinyError(\n `Field selected for the description field does not exist in the model.`,\n \"VALIDATION_ERROR\",\n {\n fieldId: descriptionFieldId,\n fields\n }\n );\n }\n if (target.multipleValues) {\n throw new WebinyError(\n `Fields that accept multiple values cannot be used as the entry description.`,\n \"ENTRY_TITLE_FIELD_TYPE\",\n {\n storageId: target.storageId,\n fieldId: target.fieldId,\n type: target.type\n }\n );\n }\n\n return target.fieldId;\n};\n"],"mappings":";;;;;;;AACA;AACA;AAEO,MAAMA,iCAAiC,GAAG,CAC7CC,MAAuB,EACvBC,kBAAkC,KACN;EAC5B;AACJ;AACA;EACI,IAAID,MAAM,CAACE,MAAM,KAAK,CAAC,EAAE;IACrB,OAAO,IAAI;EACf;EACA;AACJ;AACA;EACI,IAAI,CAACD,kBAAkB,EAAE;IACrB,MAAME,gBAAgB,GAAGH,MAAM,CAACI,IAAI,CAACC,KAAK,IAAI;MAC1C,OAAO,IAAAC,kCAAgB,EAACD,KAAK,CAAC,KAAK,WAAW,IAAI,CAACA,KAAK,CAACE,cAAc;IAC3E,CAAC,CAAC;IACF,OAAO,CAAAJ,gBAAgB,aAAhBA,gBAAgB,uBAAhBA,gBAAgB,CAAEK,OAAO,KAAI,IAAI;EAC5C;EACA,MAAMC,MAAM,GAAGT,MAAM,CAACI,IAAI,CACtBC,KAAK,IAAIA,KAAK,CAACG,OAAO,KAAKP,kBAAkB,IAAI,IAAAK,kCAAgB,EAACD,KAAK,CAAC,KAAK,WAAW,CAC3F;EACD,IAAI,CAACI,MAAM,EAAE;IACT,MAAM,IAAIC,cAAW,CAChB,uEAAsE,EACvE,kBAAkB,EAClB;MACIF,OAAO,EAAEP,kBAAkB;MAC3BD;IACJ,CAAC,CACJ;EACL;EACA,IAAIS,MAAM,CAACF,cAAc,EAAE;IACvB,MAAM,IAAIG,cAAW,CAChB,6EAA4E,EAC7E,wBAAwB,EACxB;MACIC,SAAS,EAAEF,MAAM,CAACE,SAAS;MAC3BH,OAAO,EAAEC,MAAM,CAACD,OAAO;MACvBI,IAAI,EAAEH,MAAM,CAACG;IACjB,CAAC,CACJ;EACL;EAEA,OAAOH,MAAM,CAACD,OAAO;AACzB,CAAC;AAAC"}
@@ -0,0 +1,2 @@
1
+ import { CmsModelField } from "../../../types";
2
+ export declare const getContentModelImageFieldId: (fields: CmsModelField[], imageFieldId?: string | null) => string | null | undefined;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getContentModelImageFieldId = void 0;
8
+ var _getBaseFieldType = require("../../../utils/getBaseFieldType");
9
+ var _error = _interopRequireDefault(require("@webiny/error"));
10
+ const getContentModelImageFieldId = (fields, imageFieldId) => {
11
+ /**
12
+ * If there are no fields defined, we will just set as null.
13
+ */
14
+ if (fields.length === 0) {
15
+ return null;
16
+ }
17
+ /**
18
+ * If image field is not defined, let us find possible one.
19
+ */
20
+ if (!imageFieldId) {
21
+ const imageField = fields.find(field => {
22
+ var _field$settings;
23
+ return (0, _getBaseFieldType.getBaseFieldType)(field) === "file" && !field.multipleValues && ((_field$settings = field.settings) === null || _field$settings === void 0 ? void 0 : _field$settings.imagesOnly);
24
+ });
25
+ return (imageField === null || imageField === void 0 ? void 0 : imageField.fieldId) || null;
26
+ }
27
+ const target = fields.find(field => {
28
+ var _field$settings2;
29
+ return field.fieldId === imageFieldId && (0, _getBaseFieldType.getBaseFieldType)(field) === "file" && ((_field$settings2 = field.settings) === null || _field$settings2 === void 0 ? void 0 : _field$settings2.imagesOnly);
30
+ });
31
+ if (!target) {
32
+ throw new _error.default(`Field selected for the image field does not exist in the model.`, "VALIDATION_ERROR", {
33
+ fieldId: imageFieldId,
34
+ fields
35
+ });
36
+ }
37
+ if (target.multipleValues) {
38
+ throw new _error.default(`Fields that accept multiple values cannot be used as the entry image.`, "ENTRY_TITLE_FIELD_TYPE", {
39
+ storageId: target.storageId,
40
+ fieldId: target.fieldId,
41
+ type: target.type
42
+ });
43
+ }
44
+ return target.fieldId;
45
+ };
46
+ exports.getContentModelImageFieldId = getContentModelImageFieldId;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getContentModelImageFieldId","fields","imageFieldId","length","imageField","find","field","getBaseFieldType","multipleValues","settings","imagesOnly","fieldId","target","WebinyError","storageId","type"],"sources":["imageField.ts"],"sourcesContent":["import { CmsModelField } from \"~/types\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\nimport WebinyError from \"@webiny/error\";\n\nexport const getContentModelImageFieldId = (\n fields: CmsModelField[],\n imageFieldId?: string | null\n): string | null | undefined => {\n /**\n * If there are no fields defined, we will just set as null.\n */\n if (fields.length === 0) {\n return null;\n }\n /**\n * If image field is not defined, let us find possible one.\n */\n if (!imageFieldId) {\n const imageField = fields.find(field => {\n return (\n getBaseFieldType(field) === \"file\" &&\n !field.multipleValues &&\n field.settings?.imagesOnly\n );\n });\n return imageField?.fieldId || null;\n }\n const target = fields.find(\n field =>\n field.fieldId === imageFieldId &&\n getBaseFieldType(field) === \"file\" &&\n field.settings?.imagesOnly\n );\n if (!target) {\n throw new WebinyError(\n `Field selected for the image field does not exist in the model.`,\n \"VALIDATION_ERROR\",\n {\n fieldId: imageFieldId,\n fields\n }\n );\n }\n if (target.multipleValues) {\n throw new WebinyError(\n `Fields that accept multiple values cannot be used as the entry image.`,\n \"ENTRY_TITLE_FIELD_TYPE\",\n {\n storageId: target.storageId,\n fieldId: target.fieldId,\n type: target.type\n }\n );\n }\n\n return target.fieldId;\n};\n"],"mappings":";;;;;;;AACA;AACA;AAEO,MAAMA,2BAA2B,GAAG,CACvCC,MAAuB,EACvBC,YAA4B,KACA;EAC5B;AACJ;AACA;EACI,IAAID,MAAM,CAACE,MAAM,KAAK,CAAC,EAAE;IACrB,OAAO,IAAI;EACf;EACA;AACJ;AACA;EACI,IAAI,CAACD,YAAY,EAAE;IACf,MAAME,UAAU,GAAGH,MAAM,CAACI,IAAI,CAACC,KAAK,IAAI;MAAA;MACpC,OACI,IAAAC,kCAAgB,EAACD,KAAK,CAAC,KAAK,MAAM,IAClC,CAACA,KAAK,CAACE,cAAc,wBACrBF,KAAK,CAACG,QAAQ,oDAAd,gBAAgBC,UAAU;IAElC,CAAC,CAAC;IACF,OAAO,CAAAN,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEO,OAAO,KAAI,IAAI;EACtC;EACA,MAAMC,MAAM,GAAGX,MAAM,CAACI,IAAI,CACtBC,KAAK;IAAA;IAAA,OACDA,KAAK,CAACK,OAAO,KAAKT,YAAY,IAC9B,IAAAK,kCAAgB,EAACD,KAAK,CAAC,KAAK,MAAM,yBAClCA,KAAK,CAACG,QAAQ,qDAAd,iBAAgBC,UAAU;EAAA,EACjC;EACD,IAAI,CAACE,MAAM,EAAE;IACT,MAAM,IAAIC,cAAW,CAChB,iEAAgE,EACjE,kBAAkB,EAClB;MACIF,OAAO,EAAET,YAAY;MACrBD;IACJ,CAAC,CACJ;EACL;EACA,IAAIW,MAAM,CAACJ,cAAc,EAAE;IACvB,MAAM,IAAIK,cAAW,CAChB,uEAAsE,EACvE,wBAAwB,EACxB;MACIC,SAAS,EAAEF,MAAM,CAACE,SAAS;MAC3BH,OAAO,EAAEC,MAAM,CAACD,OAAO;MACvBI,IAAI,EAAEH,MAAM,CAACG;IACjB,CAAC,CACJ;EACL;EAEA,OAAOH,MAAM,CAACD,OAAO;AACzB,CAAC;AAAC"}
@@ -0,0 +1,2 @@
1
+ import { CmsModelField } from "../../../types";
2
+ export declare const getContentModelTitleFieldId: (fields: CmsModelField[], titleFieldId?: string) => string;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getContentModelTitleFieldId = void 0;
8
+ var _getBaseFieldType = require("../../../utils/getBaseFieldType");
9
+ var _error = _interopRequireDefault(require("@webiny/error"));
10
+ const defaultTitleFieldId = "id";
11
+ const allowedTitleFieldTypes = ["text", "number"];
12
+ const getContentModelTitleFieldId = (fields, titleFieldId) => {
13
+ /**
14
+ * If there are no fields defined, we will return the default field
15
+ */
16
+ if (fields.length === 0) {
17
+ return defaultTitleFieldId;
18
+ }
19
+ /**
20
+ * if there is no title field defined either in input data or existing content model data
21
+ * we will take first text field that has no multiple values enabled
22
+ * or if initial titleFieldId is the default one also try to find first available text field
23
+ */
24
+ if (!titleFieldId || titleFieldId === defaultTitleFieldId) {
25
+ const titleField = fields.find(field => {
26
+ return (0, _getBaseFieldType.getBaseFieldType)(field) === "text" && !field.multipleValues;
27
+ });
28
+ return (titleField === null || titleField === void 0 ? void 0 : titleField.fieldId) || defaultTitleFieldId;
29
+ }
30
+ /**
31
+ * check existing titleFieldId for existence in the model
32
+ * for correct type
33
+ * and that it is not multiple values field
34
+ */
35
+ const target = fields.find(f => f.fieldId === titleFieldId);
36
+ if (!target) {
37
+ throw new _error.default(`Field selected for the title field does not exist in the model.`, "VALIDATION_ERROR", {
38
+ fieldId: titleFieldId,
39
+ fields
40
+ });
41
+ }
42
+ if (allowedTitleFieldTypes.includes(target.type) === false) {
43
+ throw new _error.default(`Only ${allowedTitleFieldTypes.join(", ")} and id fields can be used as an entry title.`, "ENTRY_TITLE_FIELD_TYPE", {
44
+ storageId: target.storageId,
45
+ fieldId: target.fieldId,
46
+ type: target.type
47
+ });
48
+ }
49
+ if (target.multipleValues) {
50
+ throw new _error.default(`Fields that accept multiple values cannot be used as the entry title.`, "ENTRY_TITLE_FIELD_TYPE", {
51
+ storageId: target.storageId,
52
+ fieldId: target.fieldId,
53
+ type: target.type
54
+ });
55
+ }
56
+ return target.fieldId;
57
+ };
58
+ exports.getContentModelTitleFieldId = getContentModelTitleFieldId;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["defaultTitleFieldId","allowedTitleFieldTypes","getContentModelTitleFieldId","fields","titleFieldId","length","titleField","find","field","getBaseFieldType","multipleValues","fieldId","target","f","WebinyError","includes","type","join","storageId"],"sources":["titleField.ts"],"sourcesContent":["import { CmsModelField } from \"~/types\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\nimport WebinyError from \"@webiny/error\";\n\nconst defaultTitleFieldId = \"id\";\n\nconst allowedTitleFieldTypes = [\"text\", \"number\"];\n\nexport const getContentModelTitleFieldId = (\n fields: CmsModelField[],\n titleFieldId?: string\n): string => {\n /**\n * If there are no fields defined, we will return the default field\n */\n if (fields.length === 0) {\n return defaultTitleFieldId;\n }\n /**\n * if there is no title field defined either in input data or existing content model data\n * we will take first text field that has no multiple values enabled\n * or if initial titleFieldId is the default one also try to find first available text field\n */\n if (!titleFieldId || titleFieldId === defaultTitleFieldId) {\n const titleField = fields.find(field => {\n return getBaseFieldType(field) === \"text\" && !field.multipleValues;\n });\n return titleField?.fieldId || defaultTitleFieldId;\n }\n /**\n * check existing titleFieldId for existence in the model\n * for correct type\n * and that it is not multiple values field\n */\n const target = fields.find(f => f.fieldId === titleFieldId);\n if (!target) {\n throw new WebinyError(\n `Field selected for the title field does not exist in the model.`,\n \"VALIDATION_ERROR\",\n {\n fieldId: titleFieldId,\n fields\n }\n );\n }\n\n if (allowedTitleFieldTypes.includes(target.type) === false) {\n throw new WebinyError(\n `Only ${allowedTitleFieldTypes.join(\n \", \"\n )} and id fields can be used as an entry title.`,\n \"ENTRY_TITLE_FIELD_TYPE\",\n {\n storageId: target.storageId,\n fieldId: target.fieldId,\n type: target.type\n }\n );\n }\n\n if (target.multipleValues) {\n throw new WebinyError(\n `Fields that accept multiple values cannot be used as the entry title.`,\n \"ENTRY_TITLE_FIELD_TYPE\",\n {\n storageId: target.storageId,\n fieldId: target.fieldId,\n type: target.type\n }\n );\n }\n\n return target.fieldId;\n};\n"],"mappings":";;;;;;;AACA;AACA;AAEA,MAAMA,mBAAmB,GAAG,IAAI;AAEhC,MAAMC,sBAAsB,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC;AAE1C,MAAMC,2BAA2B,GAAG,CACvCC,MAAuB,EACvBC,YAAqB,KACZ;EACT;AACJ;AACA;EACI,IAAID,MAAM,CAACE,MAAM,KAAK,CAAC,EAAE;IACrB,OAAOL,mBAAmB;EAC9B;EACA;AACJ;AACA;AACA;AACA;EACI,IAAI,CAACI,YAAY,IAAIA,YAAY,KAAKJ,mBAAmB,EAAE;IACvD,MAAMM,UAAU,GAAGH,MAAM,CAACI,IAAI,CAACC,KAAK,IAAI;MACpC,OAAO,IAAAC,kCAAgB,EAACD,KAAK,CAAC,KAAK,MAAM,IAAI,CAACA,KAAK,CAACE,cAAc;IACtE,CAAC,CAAC;IACF,OAAO,CAAAJ,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEK,OAAO,KAAIX,mBAAmB;EACrD;EACA;AACJ;AACA;AACA;AACA;EACI,MAAMY,MAAM,GAAGT,MAAM,CAACI,IAAI,CAACM,CAAC,IAAIA,CAAC,CAACF,OAAO,KAAKP,YAAY,CAAC;EAC3D,IAAI,CAACQ,MAAM,EAAE;IACT,MAAM,IAAIE,cAAW,CAChB,iEAAgE,EACjE,kBAAkB,EAClB;MACIH,OAAO,EAAEP,YAAY;MACrBD;IACJ,CAAC,CACJ;EACL;EAEA,IAAIF,sBAAsB,CAACc,QAAQ,CAACH,MAAM,CAACI,IAAI,CAAC,KAAK,KAAK,EAAE;IACxD,MAAM,IAAIF,cAAW,CAChB,QAAOb,sBAAsB,CAACgB,IAAI,CAC/B,IAAI,CACN,+CAA8C,EAChD,wBAAwB,EACxB;MACIC,SAAS,EAAEN,MAAM,CAACM,SAAS;MAC3BP,OAAO,EAAEC,MAAM,CAACD,OAAO;MACvBK,IAAI,EAAEJ,MAAM,CAACI;IACjB,CAAC,CACJ;EACL;EAEA,IAAIJ,MAAM,CAACF,cAAc,EAAE;IACvB,MAAM,IAAII,cAAW,CAChB,uEAAsE,EACvE,wBAAwB,EACxB;MACII,SAAS,EAAEN,MAAM,CAACM,SAAS;MAC3BP,OAAO,EAAEC,MAAM,CAACD,OAAO;MACvBK,IAAI,EAAEJ,MAAM,CAACI;IACjB,CAAC,CACJ;EACL;EAEA,OAAOJ,MAAM,CAACD,OAAO;AACzB,CAAC;AAAC"}
@@ -0,0 +1 @@
1
+ export declare const validateId: (value: string) => Promise<void>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.validateId = void 0;
7
+
8
+ var _validation = require("@webiny/validation");
9
+
10
+ const validateId = async value => {
11
+ await _validation.validation.validate(value, "required,maxLength:100");
12
+
13
+ if (!value.charAt(0).match(/[a-zA-Z]/)) {
14
+ throw new Error(`Provided ID ${value} is not valid - must not start with a number.`);
15
+ }
16
+
17
+ if (value.trim().toLowerCase() === "id") {
18
+ throw new Error(`Provided ID ${value} is not valid - "id" is an auto-generated field.`);
19
+ }
20
+ };
21
+
22
+ exports.validateId = validateId;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["validateId","value","validation","validate","charAt","match","Error","trim","toLowerCase"],"sources":["idValidation.ts"],"sourcesContent":["import { validation } from \"@webiny/validation\";\n\nexport const validateId = 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;;AAEO,MAAMA,UAAU,GAAG,MAAOC,KAAP,IAAwC;EAC9D,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,CARM"}
@@ -0,0 +1,4 @@
1
+ export declare const ContentModelFieldModel: any;
2
+ export declare const CreateContentModelModel: any;
3
+ export declare const CreateContentModelModelFrom: any;
4
+ export declare const UpdateContentModelModel: any;