@webiny/api-headless-cms 0.0.0-unstable.496cf268ac → 0.0.0-unstable.606fc9c866

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/context.js +47 -43
  2. package/context.js.map +1 -1
  3. package/crud/contentEntry/referenceFieldsMapping.js +34 -5
  4. package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
  5. package/crud/contentEntry.crud.d.ts +6 -4
  6. package/crud/contentEntry.crud.js +896 -821
  7. package/crud/contentEntry.crud.js.map +1 -1
  8. package/crud/contentModel/beforeCreate.js +38 -79
  9. package/crud/contentModel/beforeCreate.js.map +1 -1
  10. package/crud/contentModel/beforeDelete.d.ts +1 -1
  11. package/crud/contentModel/beforeDelete.js +1 -5
  12. package/crud/contentModel/beforeDelete.js.map +1 -1
  13. package/crud/contentModel/beforeUpdate.js +30 -6
  14. package/crud/contentModel/beforeUpdate.js.map +1 -1
  15. package/crud/contentModel/validate/endingAllowed.d.ts +6 -0
  16. package/crud/contentModel/validate/endingAllowed.js +26 -0
  17. package/crud/contentModel/validate/endingAllowed.js.map +1 -0
  18. package/crud/contentModel/validate/isModelEndingAllowed.d.ts +6 -0
  19. package/crud/contentModel/validate/isModelEndingAllowed.js +24 -0
  20. package/crud/contentModel/validate/isModelEndingAllowed.js.map +1 -0
  21. package/crud/contentModel/validate/modelId.d.ts +11 -0
  22. package/crud/contentModel/validate/modelId.js +36 -0
  23. package/crud/contentModel/validate/modelId.js.map +1 -0
  24. package/crud/contentModel/validate/pluralApiName.d.ts +7 -0
  25. package/crud/contentModel/validate/pluralApiName.js +24 -0
  26. package/crud/contentModel/validate/pluralApiName.js.map +1 -0
  27. package/crud/contentModel/validate/singularApiName.d.ts +7 -0
  28. package/crud/contentModel/validate/singularApiName.js +24 -0
  29. package/crud/contentModel/validate/singularApiName.js.map +1 -0
  30. package/crud/contentModel/validateModelFields.js +6 -7
  31. package/crud/contentModel/validateModelFields.js.map +1 -1
  32. package/crud/contentModel/validation.d.ts +127 -95
  33. package/crud/contentModel/validation.js +4 -4
  34. package/crud/contentModel/validation.js.map +1 -1
  35. package/crud/contentModel.crud.js +334 -296
  36. package/crud/contentModel.crud.js.map +1 -1
  37. package/crud/contentModelGroup/validation.d.ts +4 -4
  38. package/crud/contentModelGroup.crud.js +170 -142
  39. package/crud/contentModelGroup.crud.js.map +1 -1
  40. package/crud/settings.crud.d.ts +1 -1
  41. package/crud/settings.crud.js +5 -10
  42. package/crud/settings.crud.js.map +1 -1
  43. package/graphql/checkEndpointAccess.d.ts +2 -0
  44. package/graphql/checkEndpointAccess.js +18 -0
  45. package/graphql/checkEndpointAccess.js.map +1 -0
  46. package/graphql/createExecutableSchema.d.ts +2 -3
  47. package/graphql/createExecutableSchema.js.map +1 -1
  48. package/graphql/createRequestBody.d.ts +2 -0
  49. package/graphql/createRequestBody.js +14 -0
  50. package/graphql/createRequestBody.js.map +1 -0
  51. package/graphql/formatErrorPayload.d.ts +1 -0
  52. package/graphql/formatErrorPayload.js +25 -0
  53. package/graphql/formatErrorPayload.js.map +1 -0
  54. package/graphql/generateSchema.js.map +1 -1
  55. package/graphql/getSchema.d.ts +17 -0
  56. package/graphql/getSchema.js +102 -0
  57. package/graphql/getSchema.js.map +1 -0
  58. package/graphql/graphQLHandlerFactory.js +6 -150
  59. package/graphql/graphQLHandlerFactory.js.map +1 -1
  60. package/graphql/handleRequest.d.ts +11 -0
  61. package/graphql/handleRequest.js +81 -0
  62. package/graphql/handleRequest.js.map +1 -0
  63. package/graphql/index.d.ts +1 -1
  64. package/graphql/schema/contentModelGroups.js +6 -6
  65. package/graphql/schema/contentModelGroups.js.map +1 -1
  66. package/graphql/schema/contentModels.js +3 -3
  67. package/graphql/schema/contentModels.js.map +1 -1
  68. package/graphql/schema/createFieldResolvers.js +2 -1
  69. package/graphql/schema/createFieldResolvers.js.map +1 -1
  70. package/graphql/schema/createManageResolvers.js +6 -0
  71. package/graphql/schema/createManageResolvers.js.map +1 -1
  72. package/graphql/schema/resolvers/manage/resolveGetUniqueFieldValues.d.ts +4 -0
  73. package/graphql/schema/resolvers/manage/resolveGetUniqueFieldValues.js +18 -0
  74. package/graphql/schema/resolvers/manage/resolveGetUniqueFieldValues.js.map +1 -0
  75. package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +1 -1
  76. package/graphqlFields/dynamicZone/dynamicZoneField.js +44 -17
  77. package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -1
  78. package/graphqlFields/object.js +14 -1
  79. package/graphqlFields/object.js.map +1 -1
  80. package/graphqlFields/ref.js +7 -7
  81. package/graphqlFields/ref.js.map +1 -1
  82. package/index.d.ts +3 -1
  83. package/index.js +24 -0
  84. package/index.js.map +1 -1
  85. package/package.json +22 -22
  86. package/plugins/CmsModelPlugin.d.ts +15 -7
  87. package/plugins/CmsModelPlugin.js +21 -6
  88. package/plugins/CmsModelPlugin.js.map +1 -1
  89. package/plugins/StorageOperationsCmsModelPlugin.d.ts +23 -0
  90. package/plugins/StorageOperationsCmsModelPlugin.js +42 -0
  91. package/plugins/StorageOperationsCmsModelPlugin.js.map +1 -0
  92. package/plugins/index.d.ts +1 -0
  93. package/plugins/index.js +11 -0
  94. package/plugins/index.js.map +1 -1
  95. package/types.d.ts +72 -48
  96. package/types.js +4 -0
  97. package/types.js.map +1 -1
  98. package/utils/converters/valueKeyStorageConverter.d.ts +1 -5
  99. package/utils/converters/valueKeyStorageConverter.js +19 -17
  100. package/utils/converters/valueKeyStorageConverter.js.map +1 -1
  101. package/utils/createTypeFromFields.js +1 -2
  102. package/utils/createTypeFromFields.js.map +1 -1
  103. package/utils/createTypeName.d.ts +0 -2
  104. package/utils/createTypeName.js +2 -10
  105. package/utils/createTypeName.js.map +1 -1
  106. package/utils/incrementEntryIdVersion.d.ts +5 -0
  107. package/utils/incrementEntryIdVersion.js +29 -0
  108. package/utils/incrementEntryIdVersion.js.map +1 -0
  109. package/crud/contentModel/createFieldModels.d.ts +0 -2
  110. package/crud/contentModel/createFieldModels.js +0 -26
  111. package/crud/contentModel/createFieldModels.js.map +0 -1
  112. package/crud/contentModel/fieldIdValidation.d.ts +0 -1
  113. package/crud/contentModel/fieldIdValidation.js +0 -25
  114. package/crud/contentModel/fieldIdValidation.js.map +0 -1
  115. package/crud/contentModel/idValidation.d.ts +0 -1
  116. package/crud/contentModel/idValidation.js +0 -22
  117. package/crud/contentModel/idValidation.js.map +0 -1
  118. package/crud/contentModel/models.d.ts +0 -4
  119. package/crud/contentModel/models.js +0 -192
  120. package/crud/contentModel/models.js.map +0 -1
  121. package/crud/contentModel/systemFields.d.ts +0 -1
  122. package/crud/contentModel/systemFields.js +0 -8
  123. package/crud/contentModel/systemFields.js.map +0 -1
  124. package/upgrades/5.33.0/index.d.ts +0 -3
  125. package/upgrades/5.33.0/index.js +0 -182
  126. package/upgrades/5.33.0/index.js.map +0 -1
  127. package/upgrades/index.d.ts +0 -1
  128. package/upgrades/index.js +0 -12
  129. package/upgrades/index.js.map +0 -1
  130. package/utils/pluralizedTypeName.d.ts +0 -1
  131. package/utils/pluralizedTypeName.js +0 -26
  132. package/utils/pluralizedTypeName.js.map +0 -1
  133. package/utils/removeNullValues.d.ts +0 -1
  134. package/utils/removeNullValues.js +0 -17
  135. package/utils/removeNullValues.js.map +0 -1
  136. package/utils/removeUndefinedValues.d.ts +0 -1
  137. package/utils/removeUndefinedValues.js +0 -17
  138. package/utils/removeUndefinedValues.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import { Topic } from "@webiny/pubsub/types";
2
- import { OnModelBeforeDeleteTopicParams, HeadlessCmsStorageOperations } from "../../types";
2
+ import { HeadlessCmsStorageOperations, OnModelBeforeDeleteTopicParams } from "../../types";
3
3
  import { PluginsContainer } from "@webiny/plugins";
4
4
  interface AssignBeforeModelDeleteParams {
5
5
  onModelBeforeDelete: Topic<OnModelBeforeDeleteTopicParams>;
@@ -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,28 +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);
22
- context.security.disableAuthorization();
23
- const models = await context.cms.listModels();
24
- context.security.enableAuthorization();
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
+ }
25
49
  /**
26
50
  * then the model and fields...
27
51
  */
28
52
  await (0, _validateModel.validateModel)({
29
53
  models,
30
- model,
54
+ model: newModel,
31
55
  original,
32
56
  context
33
57
  });
@@ -1 +1 @@
1
- {"version":3,"names":["assignModelBeforeUpdate","params","onModelBeforeUpdate","context","subscribe","model","original","validateLayout","layout","fields","security","disableAuthorization","models","cms","listModels","enableAuthorization","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 context.security.disableAuthorization();\n const models = await context.cms.listModels();\n context.security.enableAuthorization();\n /**\n * then the model and fields...\n */\n await validateModel({\n models,\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;IAE1CN,OAAO,CAACO,QAAQ,CAACC,oBAAoB,EAAE;IACvC,MAAMC,MAAM,GAAG,MAAMT,OAAO,CAACU,GAAG,CAACC,UAAU,EAAE;IAC7CX,OAAO,CAACO,QAAQ,CAACK,mBAAmB,EAAE;IACtC;AACR;AACA;IACQ,MAAM,IAAAC,4BAAa,EAAC;MAChBJ,MAAM;MACNP,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,6 @@
1
+ import { CmsModel } from "../../../types";
2
+ interface Params {
3
+ model: Pick<CmsModel, "singularApiName" | "pluralApiName">;
4
+ }
5
+ export declare const validateEndingAllowed: (params: Params) => void;
6
+ export {};
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.validateEndingAllowed = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ var _isModelEndingAllowed = require("./isModelEndingAllowed");
10
+ const validateEndingAllowed = params => {
11
+ const {
12
+ model
13
+ } = params;
14
+ if ((0, _isModelEndingAllowed.isModelEndingAllowed)(model.singularApiName) === false) {
15
+ throw new _error.default(`Content model with singularApiName "${model.singularApiName}" is not allowed, as it ends in disallowed value.`, "MODEL_SINGULAR_API_NAME_ENDING_NOT_ALLOWED", {
16
+ input: model.singularApiName,
17
+ disallowedEnding: _isModelEndingAllowed.disallowedEnding
18
+ });
19
+ } else if ((0, _isModelEndingAllowed.isModelEndingAllowed)(model.pluralApiName) === false) {
20
+ throw new _error.default(`Content model with pluralApiName "${model.pluralApiName}" is not allowed, as it ends in disallowed value.`, "MODEL_PLURAL_API_NAME_NOT_ENDING_ALLOWED", {
21
+ input: model.pluralApiName,
22
+ disallowedEnding: _isModelEndingAllowed.disallowedEnding
23
+ });
24
+ }
25
+ };
26
+ exports.validateEndingAllowed = validateEndingAllowed;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["validateEndingAllowed","params","model","isModelEndingAllowed","singularApiName","WebinyError","input","disallowedEnding","pluralApiName"],"sources":["endingAllowed.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { disallowedEnding, isModelEndingAllowed } from \"./isModelEndingAllowed\";\nimport { CmsModel } from \"~/types\";\n\ninterface Params {\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validateEndingAllowed = (params: Params): void => {\n const { model } = params;\n if (isModelEndingAllowed(model.singularApiName) === false) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.singularApiName}\" is not allowed, as it ends in disallowed value.`,\n \"MODEL_SINGULAR_API_NAME_ENDING_NOT_ALLOWED\",\n {\n input: model.singularApiName,\n disallowedEnding\n }\n );\n } else if (isModelEndingAllowed(model.pluralApiName) === false) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.pluralApiName}\" is not allowed, as it ends in disallowed value.`,\n \"MODEL_PLURAL_API_NAME_NOT_ENDING_ALLOWED\",\n {\n input: model.pluralApiName,\n disallowedEnding: disallowedEnding\n }\n );\n }\n};\n"],"mappings":";;;;;;;AAAA;AACA;AAOO,MAAMA,qBAAqB,GAAIC,MAAc,IAAW;EAC3D,MAAM;IAAEC;EAAM,CAAC,GAAGD,MAAM;EACxB,IAAI,IAAAE,0CAAoB,EAACD,KAAK,CAACE,eAAe,CAAC,KAAK,KAAK,EAAE;IACvD,MAAM,IAAIC,cAAW,CAChB,uCAAsCH,KAAK,CAACE,eAAgB,mDAAkD,EAC/G,4CAA4C,EAC5C;MACIE,KAAK,EAAEJ,KAAK,CAACE,eAAe;MAC5BG,gBAAgB,EAAhBA;IACJ,CAAC,CACJ;EACL,CAAC,MAAM,IAAI,IAAAJ,0CAAoB,EAACD,KAAK,CAACM,aAAa,CAAC,KAAK,KAAK,EAAE;IAC5D,MAAM,IAAIH,cAAW,CAChB,qCAAoCH,KAAK,CAACM,aAAc,mDAAkD,EAC3G,0CAA0C,EAC1C;MACIF,KAAK,EAAEJ,KAAK,CAACM,aAAa;MAC1BD,gBAAgB,EAAEA;IACtB,CAAC,CACJ;EACL;AACJ,CAAC;AAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * This list is to disallow creating models that might interfere with GraphQL schema creation.
3
+ * Add more if required.
4
+ */
5
+ export declare const disallowedEnding: string[];
6
+ export declare const isModelEndingAllowed: (apiName: string) => boolean;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isModelEndingAllowed = exports.disallowedEnding = void 0;
7
+ /**
8
+ * This list is to disallow creating models that might interfere with GraphQL schema creation.
9
+ * Add more if required.
10
+ */
11
+ const disallowedEnding = ["Response", "List", "Meta", "Input", "Sorter", "RefType"];
12
+ exports.disallowedEnding = disallowedEnding;
13
+ const isModelEndingAllowed = apiName => {
14
+ for (const ending of disallowedEnding) {
15
+ const re = new RegExp(`${ending}$`, "i");
16
+ const matched = apiName.match(re);
17
+ if (matched === null) {
18
+ continue;
19
+ }
20
+ return false;
21
+ }
22
+ return true;
23
+ };
24
+ exports.isModelEndingAllowed = isModelEndingAllowed;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["disallowedEnding","isModelEndingAllowed","apiName","ending","re","RegExp","matched","match"],"sources":["isModelEndingAllowed.ts"],"sourcesContent":["/**\n * This list is to disallow creating models that might interfere with GraphQL schema creation.\n * Add more if required.\n */\nexport const disallowedEnding: string[] = [\n \"Response\",\n \"List\",\n \"Meta\",\n \"Input\",\n \"Sorter\",\n \"RefType\"\n];\n\nexport const isModelEndingAllowed = (apiName: string): boolean => {\n for (const ending of disallowedEnding) {\n const re = new RegExp(`${ending}$`, \"i\");\n const matched = apiName.match(re);\n if (matched === null) {\n continue;\n }\n return false;\n }\n return true;\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACO,MAAMA,gBAA0B,GAAG,CACtC,UAAU,EACV,MAAM,EACN,MAAM,EACN,OAAO,EACP,QAAQ,EACR,SAAS,CACZ;AAAC;AAEK,MAAMC,oBAAoB,GAAIC,OAAe,IAAc;EAC9D,KAAK,MAAMC,MAAM,IAAIH,gBAAgB,EAAE;IACnC,MAAMI,EAAE,GAAG,IAAIC,MAAM,CAAE,GAAEF,MAAO,GAAE,EAAE,GAAG,CAAC;IACxC,MAAMG,OAAO,GAAGJ,OAAO,CAACK,KAAK,CAACH,EAAE,CAAC;IACjC,IAAIE,OAAO,KAAK,IAAI,EAAE;MAClB;IACJ;IACA,OAAO,KAAK;EAChB;EACA,OAAO,IAAI;AACf,CAAC;AAAC"}
@@ -0,0 +1,11 @@
1
+ import { CmsModel } from "../../../types";
2
+ interface ModelIdAllowedParams {
3
+ model: Pick<CmsModel, "modelId">;
4
+ }
5
+ export declare const validateModelIdAllowed: (params: ModelIdAllowedParams) => void;
6
+ interface Params {
7
+ existingModel: Pick<CmsModel, "modelId">;
8
+ model: Pick<CmsModel, "modelId">;
9
+ }
10
+ export declare const validateExistingModelId: (params: Params) => void;
11
+ export {};
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.validateModelIdAllowed = exports.validateExistingModelId = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ const disallowedModelIdList = ["contentModel", "contentModels", "contentModelGroup", "contentModelGroups"];
10
+ const isModelIdAllowed = modelId => {
11
+ return disallowedModelIdList.includes(modelId) === false;
12
+ };
13
+ const validateModelIdAllowed = params => {
14
+ const {
15
+ model
16
+ } = params;
17
+ if (isModelIdAllowed(model.modelId)) {
18
+ return;
19
+ }
20
+ throw new _error.default(`Provided model ID "${model.modelId}" is not allowed.`, "MODEL_ID_NOT_ALLOWED", {
21
+ input: model.modelId
22
+ });
23
+ };
24
+ exports.validateModelIdAllowed = validateModelIdAllowed;
25
+ const validateExistingModelId = params => {
26
+ const {
27
+ existingModel,
28
+ model
29
+ } = params;
30
+ if (existingModel.modelId === model.modelId) {
31
+ throw new _error.default(`Content model with modelId "${model.modelId}" already exists.`, "MODEL_ID_EXISTS", {
32
+ input: existingModel.modelId
33
+ });
34
+ }
35
+ };
36
+ exports.validateExistingModelId = validateExistingModelId;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["disallowedModelIdList","isModelIdAllowed","modelId","includes","validateModelIdAllowed","params","model","WebinyError","input","validateExistingModelId","existingModel"],"sources":["modelId.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsModel } from \"~/types\";\n\nconst disallowedModelIdList: string[] = [\n \"contentModel\",\n \"contentModels\",\n \"contentModelGroup\",\n \"contentModelGroups\"\n];\nconst isModelIdAllowed = (modelId: string): boolean => {\n return disallowedModelIdList.includes(modelId) === false;\n};\n\ninterface ModelIdAllowedParams {\n model: Pick<CmsModel, \"modelId\">;\n}\n\nexport const validateModelIdAllowed = (params: ModelIdAllowedParams) => {\n const { model } = params;\n if (isModelIdAllowed(model.modelId)) {\n return;\n }\n throw new WebinyError(\n `Provided model ID \"${model.modelId}\" is not allowed.`,\n \"MODEL_ID_NOT_ALLOWED\",\n {\n input: model.modelId\n }\n );\n};\n\ninterface Params {\n existingModel: Pick<CmsModel, \"modelId\">;\n model: Pick<CmsModel, \"modelId\">;\n}\n\nexport const validateExistingModelId = (params: Params): void => {\n const { existingModel, model } = params;\n\n if (existingModel.modelId === model.modelId) {\n throw new WebinyError(\n `Content model with modelId \"${model.modelId}\" already exists.`,\n \"MODEL_ID_EXISTS\",\n {\n input: existingModel.modelId\n }\n );\n }\n};\n"],"mappings":";;;;;;;AAAA;AAGA,MAAMA,qBAA+B,GAAG,CACpC,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,oBAAoB,CACvB;AACD,MAAMC,gBAAgB,GAAIC,OAAe,IAAc;EACnD,OAAOF,qBAAqB,CAACG,QAAQ,CAACD,OAAO,CAAC,KAAK,KAAK;AAC5D,CAAC;AAMM,MAAME,sBAAsB,GAAIC,MAA4B,IAAK;EACpE,MAAM;IAAEC;EAAM,CAAC,GAAGD,MAAM;EACxB,IAAIJ,gBAAgB,CAACK,KAAK,CAACJ,OAAO,CAAC,EAAE;IACjC;EACJ;EACA,MAAM,IAAIK,cAAW,CAChB,sBAAqBD,KAAK,CAACJ,OAAQ,mBAAkB,EACtD,sBAAsB,EACtB;IACIM,KAAK,EAAEF,KAAK,CAACJ;EACjB,CAAC,CACJ;AACL,CAAC;AAAC;AAOK,MAAMO,uBAAuB,GAAIJ,MAAc,IAAW;EAC7D,MAAM;IAAEK,aAAa;IAAEJ;EAAM,CAAC,GAAGD,MAAM;EAEvC,IAAIK,aAAa,CAACR,OAAO,KAAKI,KAAK,CAACJ,OAAO,EAAE;IACzC,MAAM,IAAIK,cAAW,CAChB,+BAA8BD,KAAK,CAACJ,OAAQ,mBAAkB,EAC/D,iBAAiB,EACjB;MACIM,KAAK,EAAEE,aAAa,CAACR;IACzB,CAAC,CACJ;EACL;AACJ,CAAC;AAAC"}
@@ -0,0 +1,7 @@
1
+ import { CmsModel } from "../../../types";
2
+ interface Params {
3
+ existingModel: Pick<CmsModel, "singularApiName" | "pluralApiName">;
4
+ model: Pick<CmsModel, "singularApiName" | "pluralApiName">;
5
+ }
6
+ export declare const validatePluralApiName: (params: Params) => void;
7
+ export {};
@@ -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.validatePluralApiName = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ const validatePluralApiName = params => {
10
+ const {
11
+ existingModel,
12
+ model
13
+ } = params;
14
+ if (existingModel.singularApiName === model.pluralApiName) {
15
+ throw new _error.default(`Content model with singularApiName "${model.pluralApiName}" already exists.`, "MODEL_SINGULAR_API_NAME_EXISTS", {
16
+ input: model.pluralApiName
17
+ });
18
+ } else if (existingModel.pluralApiName === model.pluralApiName) {
19
+ throw new _error.default(`Content model with pluralApiName "${model.pluralApiName}" already exists.`, "MODEL_PLURAL_API_NAME_EXISTS", {
20
+ input: model.pluralApiName
21
+ });
22
+ }
23
+ };
24
+ exports.validatePluralApiName = validatePluralApiName;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["validatePluralApiName","params","existingModel","model","singularApiName","pluralApiName","WebinyError","input"],"sources":["pluralApiName.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsModel } from \"~/types\";\n\ninterface Params {\n existingModel: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validatePluralApiName = (params: Params): void => {\n const { existingModel, model } = params;\n\n if (existingModel.singularApiName === model.pluralApiName) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.pluralApiName}\" already exists.`,\n \"MODEL_SINGULAR_API_NAME_EXISTS\",\n {\n input: model.pluralApiName\n }\n );\n } else if (existingModel.pluralApiName === model.pluralApiName) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.pluralApiName}\" already exists.`,\n \"MODEL_PLURAL_API_NAME_EXISTS\",\n {\n input: model.pluralApiName\n }\n );\n }\n};\n"],"mappings":";;;;;;;AAAA;AAQO,MAAMA,qBAAqB,GAAIC,MAAc,IAAW;EAC3D,MAAM;IAAEC,aAAa;IAAEC;EAAM,CAAC,GAAGF,MAAM;EAEvC,IAAIC,aAAa,CAACE,eAAe,KAAKD,KAAK,CAACE,aAAa,EAAE;IACvD,MAAM,IAAIC,cAAW,CAChB,uCAAsCH,KAAK,CAACE,aAAc,mBAAkB,EAC7E,gCAAgC,EAChC;MACIE,KAAK,EAAEJ,KAAK,CAACE;IACjB,CAAC,CACJ;EACL,CAAC,MAAM,IAAIH,aAAa,CAACG,aAAa,KAAKF,KAAK,CAACE,aAAa,EAAE;IAC5D,MAAM,IAAIC,cAAW,CAChB,qCAAoCH,KAAK,CAACE,aAAc,mBAAkB,EAC3E,8BAA8B,EAC9B;MACIE,KAAK,EAAEJ,KAAK,CAACE;IACjB,CAAC,CACJ;EACL;AACJ,CAAC;AAAC"}
@@ -0,0 +1,7 @@
1
+ import { CmsModel } from "../../../types";
2
+ interface Params {
3
+ existingModel: Pick<CmsModel, "singularApiName" | "pluralApiName">;
4
+ model: Pick<CmsModel, "singularApiName" | "pluralApiName">;
5
+ }
6
+ export declare const validateSingularApiName: (params: Params) => void;
7
+ export {};
@@ -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.validateSingularApiName = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ const validateSingularApiName = params => {
10
+ const {
11
+ existingModel,
12
+ model
13
+ } = params;
14
+ if (existingModel.singularApiName === model.singularApiName) {
15
+ throw new _error.default(`Content model with singularApiName "${model.singularApiName}" already exists.`, "MODEL_SINGULAR_API_NAME_EXISTS", {
16
+ input: model.singularApiName
17
+ });
18
+ } else if (existingModel.pluralApiName === model.singularApiName) {
19
+ throw new _error.default(`Content model with pluralApiName "${model.singularApiName}" already exists.`, "MODEL_PLURAL_API_NAME_EXISTS", {
20
+ input: model.singularApiName
21
+ });
22
+ }
23
+ };
24
+ exports.validateSingularApiName = validateSingularApiName;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["validateSingularApiName","params","existingModel","model","singularApiName","WebinyError","input","pluralApiName"],"sources":["singularApiName.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsModel } from \"~/types\";\n\ninterface Params {\n existingModel: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validateSingularApiName = (params: Params): void => {\n const { existingModel, model } = params;\n\n if (existingModel.singularApiName === model.singularApiName) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.singularApiName}\" already exists.`,\n \"MODEL_SINGULAR_API_NAME_EXISTS\",\n {\n input: model.singularApiName\n }\n );\n } else if (existingModel.pluralApiName === model.singularApiName) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.singularApiName}\" already exists.`,\n \"MODEL_PLURAL_API_NAME_EXISTS\",\n {\n input: model.singularApiName\n }\n );\n }\n};\n"],"mappings":";;;;;;;AAAA;AAQO,MAAMA,uBAAuB,GAAIC,MAAc,IAAW;EAC7D,MAAM;IAAEC,aAAa;IAAEC;EAAM,CAAC,GAAGF,MAAM;EAEvC,IAAIC,aAAa,CAACE,eAAe,KAAKD,KAAK,CAACC,eAAe,EAAE;IACzD,MAAM,IAAIC,cAAW,CAChB,uCAAsCF,KAAK,CAACC,eAAgB,mBAAkB,EAC/E,gCAAgC,EAChC;MACIE,KAAK,EAAEH,KAAK,CAACC;IACjB,CAAC,CACJ;EACL,CAAC,MAAM,IAAIF,aAAa,CAACK,aAAa,KAAKJ,KAAK,CAACC,eAAe,EAAE;IAC9D,MAAM,IAAIC,cAAW,CAChB,qCAAoCF,KAAK,CAACC,eAAgB,mBAAkB,EAC7E,8BAA8B,EAC9B;MACIE,KAAK,EAAEH,KAAK,CAACC;IACjB,CAAC,CACJ;EACL;AACJ,CAAC;AAAC"}
@@ -17,7 +17,6 @@ var _imageField = require("./fields/imageField");
17
17
  var _plugins = require("../../plugins");
18
18
  var _buildSchemaPlugins = require("../../graphql/buildSchemaPlugins");
19
19
  var _createExecutableSchema = require("../../graphql/createExecutableSchema");
20
- var _handlerGraphql = require("@webiny/handler-graphql");
21
20
  var _utils = require("@webiny/utils");
22
21
  const extractInvalidField = (model, err) => {
23
22
  var _err$source;
@@ -188,17 +187,17 @@ const createGraphQLSchema = async params => {
188
187
  context,
189
188
  model
190
189
  } = params;
191
- context.security.disableAuthorization();
192
- const models = (await context.cms.listModels()).filter(model => {
193
- return !model.isPrivate;
190
+ const models = await context.security.withoutAuthorization(async () => {
191
+ return (await context.cms.listModels()).filter(model => {
192
+ return model.isPrivate !== true;
193
+ });
194
194
  });
195
- context.security.enableAuthorization();
196
195
  const modelPlugins = await (0, _buildSchemaPlugins.buildSchemaPlugins)({
197
196
  context,
198
197
  models: models.concat([model])
199
198
  });
200
- const plugins = context.plugins.byType(_handlerGraphql.GraphQLSchemaPlugin.type).reduce((collection, plugin) => {
201
- const name = plugin.name || `${plugin.type}-${(0, _utils.generateAlphaNumericId)(16)}`;
199
+ const plugins = context.plugins.byType(_plugins.CmsGraphQLSchemaPlugin.type).reduce((collection, plugin) => {
200
+ const name = plugin.name || `${_plugins.CmsGraphQLSchemaPlugin.type}-${(0, _utils.generateAlphaNumericId)(16)}`;
202
201
  collection[name] = plugin;
203
202
  return collection;
204
203
  }, {});
@@ -1 +1 @@
1
- {"version":3,"names":["extractInvalidField","model","err","sdl","source","body","line","lineNumber","locations","sdlLines","split","sdlLine","gqlType","i","includes","match","invalidField","undefined","Array","isArray","fieldRegex","RegExp","matched","message","data","modelId","code","join","createValidateChildFields","plugins","fields","originalFields","length","validateFields","lockedFields","params","idList","fieldIdList","storageIdList","field","baseType","getBaseFieldType","plugin","find","fieldType","Error","id","WebinyError","storageId","fieldId","push","originalField","f","isLocked","some","lockedField","createFieldStorageId","label","validateChildFields","validate","createGraphQLSchema","context","security","disableAuthorization","models","cms","listModels","filter","isPrivate","enableAuthorization","modelPlugins","buildSchemaPlugins","concat","byType","GraphQLSchemaPlugin","type","reduce","collection","name","generateAlphaNumericId","createExecutableSchema","Object","values","extractErrorObject","error","output","key","validateModelFields","original","titleFieldId","descriptionFieldId","imageFieldId","fieldTypePlugins","sorterPlugins","CmsGraphQLSchemaSorterPlugin","schema","createManageSDL","acc","pl","gql","getContentModelTitleFieldId","getContentModelDescriptionFieldId","getContentModelImageFieldId","cmsLockedFieldPlugins","existingField","item","multipleValues","reason","lockedFieldType","existingFieldType","lockedFieldsByType","checkLockedField"],"sources":["validateModelFields.ts"],"sourcesContent":["import gql from \"graphql-tag\";\nimport WebinyError from \"@webiny/error\";\nimport {\n CmsModel,\n CmsContext,\n CmsModelField,\n CmsModelFieldToGraphQLPlugin,\n CmsModelFieldToGraphQLPluginValidateChildFieldsValidate,\n CmsModelLockedFieldPlugin,\n LockedField\n} from \"~/types\";\nimport { createManageSDL } from \"~/graphql/schema/createManageSDL\";\nimport { createFieldStorageId } from \"./createFieldStorageId\";\nimport { GraphQLError } from \"graphql\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\nimport { getContentModelTitleFieldId } from \"./fields/titleField\";\nimport { getContentModelDescriptionFieldId } from \"./fields/descriptionField\";\nimport { getContentModelImageFieldId } from \"./fields/imageField\";\nimport { CmsGraphQLSchemaSorterPlugin } from \"~/plugins\";\nimport { buildSchemaPlugins } from \"~/graphql/buildSchemaPlugins\";\nimport { createExecutableSchema } from \"~/graphql/createExecutableSchema\";\nimport { GraphQLSchemaPlugin } from \"@webiny/handler-graphql\";\nimport { generateAlphaNumericId } from \"@webiny/utils\";\n\nconst extractInvalidField = (model: CmsModel, err: GraphQLError) => {\n const sdl = err.source?.body || \"\";\n\n /**\n * Find the invalid type\n */\n const { line: lineNumber } = err.locations\n ? err.locations[0]\n : {\n line: 0\n };\n const sdlLines = sdl.split(\"\\n\");\n let sdlLine;\n let gqlType;\n for (let i = lineNumber; i > 0; i--) {\n if (sdlLine && sdlLine.includes(\"type \")) {\n gqlType = sdlLine.match(/type\\s+(.*?)\\s+{/);\n break;\n }\n\n sdlLine = sdlLines[i];\n }\n\n let invalidField: string | undefined = undefined;\n if (Array.isArray(gqlType)) {\n const fieldRegex = new RegExp(`([^\\\\s+].*?):\\\\s+\\\\[?${gqlType[1]}!?\\\\]?`);\n\n const matched = sdl.match(fieldRegex);\n if (matched) {\n invalidField = matched[1];\n }\n }\n\n let message = `See more details in the browser console.`;\n if (invalidField) {\n message = `Please review the definition of \"${invalidField}\" field.`;\n }\n\n return {\n data: {\n modelId: model.modelId,\n sdl,\n invalidField\n },\n code: \"INVALID_MODEL_DEFINITION\",\n message: [`Model \"${model.modelId}\" was not saved!`, message].join(\"\\n\")\n };\n};\n\nconst createValidateChildFields = (\n plugins: CmsModelFieldToGraphQLPlugin[]\n): CmsModelFieldToGraphQLPluginValidateChildFieldsValidate => {\n return ({ fields, originalFields }) => {\n if (fields.length === 0 && originalFields.length === 0) {\n return;\n }\n validateFields({\n fields,\n originalFields,\n plugins,\n lockedFields: []\n });\n };\n};\n\ninterface ValidateFieldsParams {\n plugins: CmsModelFieldToGraphQLPlugin[];\n fields: CmsModelField[];\n originalFields: CmsModelField[];\n lockedFields: LockedField[];\n}\n\nconst validateFields = (params: ValidateFieldsParams) => {\n const { plugins, fields, originalFields, lockedFields } = params;\n\n const idList: string[] = [];\n const fieldIdList: string[] = [];\n const storageIdList: string[] = [];\n\n for (const field of fields) {\n const baseType = getBaseFieldType(field);\n const plugin = plugins.find(plugin => plugin.fieldType === baseType);\n\n if (!plugin) {\n throw new Error(\n `Cannot update content model because of the unknown \"${baseType}\" field.`\n );\n }\n /**\n * Check the field's id against existing ones.\n * There cannot be two fields with the same id.\n */\n if (idList.includes(field.id)) {\n throw new WebinyError(\n `Cannot update content model because field \"${\n field.storageId || field.fieldId\n }\" has id \"${field.id}\", which is already used.`\n );\n }\n idList.push(field.id);\n\n const originalField = originalFields.find(f => f.id === field.id);\n /**\n * Field MUST have an fieldId defined.\n */\n if (!field.fieldId) {\n throw new WebinyError(`Field does not have an \"fieldId\" defined.`, \"MISSING_FIELD_ID\", {\n field\n });\n }\n /**\n * If storageId does not match a certain pattern, add that pattern, but only if field is not locked (used) already.\n * This is to avoid errors in the already installed systems.\n *\n * Why are we using the @?\n *\n * It is not part of special characters for the query syntax in the Lucene.\n *\n * Relevant links:\n * https://lucene.apache.org/core/3_4_0/queryparsersyntax.html\n * https://discuss.elastic.co/t/special-characters-in-field-names/10658/3\n * https://discuss.elastic.co/t/illegal-characters-in-elasticsearch-field-names/17196/2\n */\n const isLocked = lockedFields.some(lockedField => {\n return lockedField.fieldId === field.storageId || lockedField.fieldId === field.fieldId;\n });\n if (!field.storageId) {\n /**\n * In case field is locked, we must set the storageId to the fieldId value.\n * This should not happen, because we upgrade all the fields in 5.33.0, but let's have a check just in case of some upgrade miss.\n */\n //\n if (isLocked) {\n field.storageId = field.fieldId;\n }\n /**\n * When having original field, just set the storageId to value from the originalField\n */\n //\n else if (originalField) {\n field.storageId = originalField.storageId;\n }\n /**\n * The last case is when no original field and not locked - so this is a completely new field.\n */\n //\n else {\n field.storageId = createFieldStorageId(field);\n }\n }\n /**\n * Check the field's fieldId against existing ones.\n * There cannot be two fields with the same fieldId - outside world identifier.\n */\n if (fieldIdList.includes(field.fieldId)) {\n throw new WebinyError(\n `Cannot update content model because field \"${field.storageId}\" has fieldId \"${field.fieldId}\", which is already used.`\n );\n }\n fieldIdList.push(field.fieldId);\n /**\n * Check the field's storageId against the existing ones.\n * There cannot be two fields with the same storageId.\n */\n if (storageIdList.includes(field.storageId)) {\n throw new WebinyError(\n `Cannot update content model because field \"${field.label}\" has storageId \"${field.storageId}\", which is already used.`\n );\n }\n storageIdList.push(field.storageId);\n /**\n * There might be some plugins which allow child fields.\n * We use this method to validate them as well.\n */\n if (!plugin.validateChildFields) {\n continue;\n }\n const validateChildFields = createValidateChildFields(plugins);\n plugin.validateChildFields({\n field,\n originalField,\n validate: validateChildFields\n });\n }\n};\n\ninterface CreateGraphQLSchemaParams {\n context: CmsContext;\n model: CmsModel;\n}\n\nconst createGraphQLSchema = async (params: CreateGraphQLSchemaParams): Promise<any> => {\n const { context, model } = params;\n\n context.security.disableAuthorization();\n const models = (await context.cms.listModels()).filter((model): model is CmsModel => {\n return !model.isPrivate;\n });\n context.security.enableAuthorization();\n\n const modelPlugins = await buildSchemaPlugins({\n context,\n models: models.concat([model])\n });\n\n const plugins = context.plugins\n .byType<GraphQLSchemaPlugin<CmsContext>>(GraphQLSchemaPlugin.type)\n .reduce<Record<string, GraphQLSchemaPlugin<CmsContext>>>((collection, plugin) => {\n const name = plugin.name || `${plugin.type}-${generateAlphaNumericId(16)}`;\n collection[name] = plugin;\n return collection;\n }, {});\n for (const plugin of modelPlugins) {\n const name = plugin.name || `${plugin.type}-${generateAlphaNumericId(16)}`;\n plugins[name] = plugin;\n }\n\n return createExecutableSchema({\n plugins: Object.values(plugins)\n });\n};\n\nconst extractErrorObject = (error: any) => {\n return [\"message\", \"code\", \"data\", \"stack\"].reduce<Record<string, any>>((output, key) => {\n if (!error[key]) {\n return output;\n }\n output[key] = error[key];\n return output;\n }, {});\n};\n\ninterface ValidateModelFieldsParams {\n models: CmsModel[];\n model: CmsModel;\n original?: CmsModel;\n context: CmsContext;\n}\n\nexport const validateModelFields = async (params: ValidateModelFieldsParams): Promise<void> => {\n const { models, model, original, context } = params;\n const { titleFieldId, descriptionFieldId, imageFieldId } = model;\n const { plugins } = context;\n\n /**\n * There should be fields/locked fields in either model or data to be updated.\n */\n const { fields = [], lockedFields = [] } = model;\n\n /**\n * Let's inspect the fields of the received content model. We prevent saving of a content model if it\n * contains a field for which a \"cms-model-field-to-graphql\" plugin does not exist on the backend.\n */\n const fieldTypePlugins = plugins.byType<CmsModelFieldToGraphQLPlugin>(\n \"cms-model-field-to-graphql\"\n );\n\n validateFields({\n fields,\n originalFields: original?.fields || [],\n lockedFields,\n plugins: fieldTypePlugins\n });\n\n if (fields.length) {\n const sorterPlugins = plugins.byType<CmsGraphQLSchemaSorterPlugin>(\n CmsGraphQLSchemaSorterPlugin.type\n );\n /**\n * Make sure that this model can be safely converted to a GraphQL SDL\n */\n const schema = createManageSDL({\n models,\n model,\n fieldTypePlugins: fieldTypePlugins.reduce(\n (acc, pl) => ({ ...acc, [pl.fieldType]: pl }),\n {}\n ),\n sorterPlugins\n });\n\n try {\n gql(schema);\n } catch (err) {\n throw new WebinyError(extractInvalidField(model, err));\n }\n /**\n *\n */\n try {\n await createGraphQLSchema({\n context,\n model\n });\n } catch (err) {\n throw new WebinyError({\n message:\n \"Cannot generate GraphQL schema when testing with the given model. Please check the response for more details.\",\n code: \"GRAPHQL_SCHEMA_ERROR\",\n data: {\n modelId: model.modelId,\n error: extractErrorObject(err)\n }\n });\n }\n }\n\n model.titleFieldId = getContentModelTitleFieldId(fields, titleFieldId);\n model.descriptionFieldId = getContentModelDescriptionFieldId(fields, descriptionFieldId);\n model.imageFieldId = getContentModelImageFieldId(fields, imageFieldId);\n\n const cmsLockedFieldPlugins =\n plugins.byType<CmsModelLockedFieldPlugin>(\"cms-model-locked-field\");\n\n /**\n * We must not allow removal or changes in fields that are already in use in content entries.\n * Locked fields still have fieldId (should be storageId) because of the old existing locked fields in the models.\n */\n for (const lockedField of lockedFields) {\n const existingField = fields.find(item => item.storageId === lockedField.fieldId);\n\n /**\n * Starting with 5.33.0 fields can be deleted.\n * Our UI gives a warning upon locked field deletion, but if user is managing fields through API directly - we cannot do anything.\n */\n if (!existingField) {\n continue;\n }\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 reason: `\"multipleValues\" changed`,\n field: existingField\n }\n );\n }\n\n const fieldType = getBaseFieldType(existingField);\n if (lockedField.type !== fieldType) {\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 reason: `\"type\" changed`,\n lockedFieldType: lockedField.type,\n existingFieldType: fieldType\n }\n );\n }\n\n /**\n * Check `lockedField` invariant for specific field\n */\n const lockedFieldsByType = cmsLockedFieldPlugins.filter(\n pl => pl.fieldType === getBaseFieldType(lockedField)\n );\n for (const plugin of lockedFieldsByType) {\n if (typeof plugin.checkLockedField !== \"function\") {\n continue;\n }\n plugin.checkLockedField({\n lockedField,\n field: existingField\n });\n }\n }\n};\n"],"mappings":";;;;;;;;AAAA;AACA;AAUA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,MAAMA,mBAAmB,GAAG,CAACC,KAAe,EAAEC,GAAiB,KAAK;EAAA;EAChE,MAAMC,GAAG,GAAG,gBAAAD,GAAG,CAACE,MAAM,gDAAV,YAAYC,IAAI,KAAI,EAAE;;EAElC;AACJ;AACA;EACI,MAAM;IAAEC,IAAI,EAAEC;EAAW,CAAC,GAAGL,GAAG,CAACM,SAAS,GACpCN,GAAG,CAACM,SAAS,CAAC,CAAC,CAAC,GAChB;IACIF,IAAI,EAAE;EACV,CAAC;EACP,MAAMG,QAAQ,GAAGN,GAAG,CAACO,KAAK,CAAC,IAAI,CAAC;EAChC,IAAIC,OAAO;EACX,IAAIC,OAAO;EACX,KAAK,IAAIC,CAAC,GAAGN,UAAU,EAAEM,CAAC,GAAG,CAAC,EAAEA,CAAC,EAAE,EAAE;IACjC,IAAIF,OAAO,IAAIA,OAAO,CAACG,QAAQ,CAAC,OAAO,CAAC,EAAE;MACtCF,OAAO,GAAGD,OAAO,CAACI,KAAK,CAAC,kBAAkB,CAAC;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Q,yDAAwD,EACvH,kBAAkB,EAClB;QACI0D,MAAM,EAAG,0BAAyB;QAClCpE,KAAK,EAAEiE;MACX,CAAC,CACJ;IACL;IAEA,MAAM5D,SAAS,GAAG,IAAAH,kCAAgB,EAAC+D,aAAa,CAAC;IACjD,IAAIjD,WAAW,CAACoB,IAAI,KAAK/B,SAAS,EAAE;MAChC,MAAM,IAAIG,cAAW,CAChB,qCAAoCQ,WAAW,CAACN,OAAQ,yDAAwD,EACjH,kBAAkB,EAClB;QACI0D,MAAM,EAAG,gBAAe;QACxBC,eAAe,EAAErD,WAAW,CAACoB,IAAI;QACjCkC,iBAAiB,EAAEjE;MACvB,CAAC,CACJ;IACL;;IAEA;AACR;AACA;IACQ,MAAMkE,kBAAkB,GAAGP,qBAAqB,CAACpC,MAAM,CACnD+B,EAAE,IAAIA,EAAE,CAACtD,SAAS,KAAK,IAAAH,kCAAgB,EAACc,WAAW,CAAC,CACvD;IACD,KAAK,MAAMb,MAAM,IAAIoE,kBAAkB,EAAE;MACrC,IAAI,OAAOpE,MAAM,CAACqE,gBAAgB,KAAK,UAAU,EAAE;QAC/C;MACJ;MACArE,MAAM,CAACqE,gBAAgB,CAAC;QACpBxD,WAAW;QACXhB,KAAK,EAAEiE;MACX,CAAC,CAAC;IACN;EACJ;AACJ,CAAC;AAAC"}
1
+ {"version":3,"names":["extractInvalidField","model","err","sdl","source","body","line","lineNumber","locations","sdlLines","split","sdlLine","gqlType","i","includes","match","invalidField","undefined","Array","isArray","fieldRegex","RegExp","matched","message","data","modelId","code","join","createValidateChildFields","plugins","fields","originalFields","length","validateFields","lockedFields","params","idList","fieldIdList","storageIdList","field","baseType","getBaseFieldType","plugin","find","fieldType","Error","id","WebinyError","storageId","fieldId","push","originalField","f","isLocked","some","lockedField","createFieldStorageId","label","validateChildFields","validate","createGraphQLSchema","context","models","security","withoutAuthorization","cms","listModels","filter","isPrivate","modelPlugins","buildSchemaPlugins","concat","byType","CmsGraphQLSchemaPlugin","type","reduce","collection","name","generateAlphaNumericId","createExecutableSchema","Object","values","extractErrorObject","error","output","key","validateModelFields","original","titleFieldId","descriptionFieldId","imageFieldId","fieldTypePlugins","sorterPlugins","CmsGraphQLSchemaSorterPlugin","schema","createManageSDL","acc","pl","gql","getContentModelTitleFieldId","getContentModelDescriptionFieldId","getContentModelImageFieldId","cmsLockedFieldPlugins","existingField","item","multipleValues","reason","lockedFieldType","existingFieldType","lockedFieldsByType","checkLockedField"],"sources":["validateModelFields.ts"],"sourcesContent":["import gql from \"graphql-tag\";\nimport WebinyError from \"@webiny/error\";\nimport {\n CmsModel,\n CmsContext,\n CmsModelField,\n CmsModelFieldToGraphQLPlugin,\n CmsModelFieldToGraphQLPluginValidateChildFieldsValidate,\n CmsModelLockedFieldPlugin,\n LockedField\n} from \"~/types\";\nimport { createManageSDL } from \"~/graphql/schema/createManageSDL\";\nimport { createFieldStorageId } from \"./createFieldStorageId\";\nimport { GraphQLError } from \"graphql\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\nimport { getContentModelTitleFieldId } from \"./fields/titleField\";\nimport { getContentModelDescriptionFieldId } from \"./fields/descriptionField\";\nimport { getContentModelImageFieldId } from \"./fields/imageField\";\nimport { CmsGraphQLSchemaPlugin, CmsGraphQLSchemaSorterPlugin } from \"~/plugins\";\nimport { buildSchemaPlugins } from \"~/graphql/buildSchemaPlugins\";\nimport { createExecutableSchema } from \"~/graphql/createExecutableSchema\";\nimport { generateAlphaNumericId } from \"@webiny/utils\";\n\nconst extractInvalidField = (model: CmsModel, err: GraphQLError) => {\n const sdl = err.source?.body || \"\";\n\n /**\n * Find the invalid type\n */\n const { line: lineNumber } = err.locations\n ? err.locations[0]\n : {\n line: 0\n };\n const sdlLines = sdl.split(\"\\n\");\n let sdlLine;\n let gqlType;\n for (let i = lineNumber; i > 0; i--) {\n if (sdlLine && sdlLine.includes(\"type \")) {\n gqlType = sdlLine.match(/type\\s+(.*?)\\s+{/);\n break;\n }\n\n sdlLine = sdlLines[i];\n }\n\n let invalidField: string | undefined = undefined;\n if (Array.isArray(gqlType)) {\n const fieldRegex = new RegExp(`([^\\\\s+].*?):\\\\s+\\\\[?${gqlType[1]}!?\\\\]?`);\n\n const matched = sdl.match(fieldRegex);\n if (matched) {\n invalidField = matched[1];\n }\n }\n\n let message = `See more details in the browser console.`;\n if (invalidField) {\n message = `Please review the definition of \"${invalidField}\" field.`;\n }\n\n return {\n data: {\n modelId: model.modelId,\n sdl,\n invalidField\n },\n code: \"INVALID_MODEL_DEFINITION\",\n message: [`Model \"${model.modelId}\" was not saved!`, message].join(\"\\n\")\n };\n};\n\nconst createValidateChildFields = (\n plugins: CmsModelFieldToGraphQLPlugin[]\n): CmsModelFieldToGraphQLPluginValidateChildFieldsValidate => {\n return ({ fields, originalFields }) => {\n if (fields.length === 0 && originalFields.length === 0) {\n return;\n }\n validateFields({\n fields,\n originalFields,\n plugins,\n lockedFields: []\n });\n };\n};\n\ninterface ValidateFieldsParams {\n plugins: CmsModelFieldToGraphQLPlugin[];\n fields: CmsModelField[];\n originalFields: CmsModelField[];\n lockedFields: LockedField[];\n}\n\nconst validateFields = (params: ValidateFieldsParams) => {\n const { plugins, fields, originalFields, lockedFields } = params;\n\n const idList: string[] = [];\n const fieldIdList: string[] = [];\n const storageIdList: string[] = [];\n\n for (const field of fields) {\n const baseType = getBaseFieldType(field);\n const plugin = plugins.find(plugin => plugin.fieldType === baseType);\n\n if (!plugin) {\n throw new Error(\n `Cannot update content model because of the unknown \"${baseType}\" field.`\n );\n }\n /**\n * Check the field's id against existing ones.\n * There cannot be two fields with the same id.\n */\n if (idList.includes(field.id)) {\n throw new WebinyError(\n `Cannot update content model because field \"${\n field.storageId || field.fieldId\n }\" has id \"${field.id}\", which is already used.`\n );\n }\n idList.push(field.id);\n\n const originalField = originalFields.find(f => f.id === field.id);\n /**\n * Field MUST have an fieldId defined.\n */\n if (!field.fieldId) {\n throw new WebinyError(`Field does not have an \"fieldId\" defined.`, \"MISSING_FIELD_ID\", {\n field\n });\n }\n /**\n * If storageId does not match a certain pattern, add that pattern, but only if field is not locked (used) already.\n * This is to avoid errors in the already installed systems.\n *\n * Why are we using the @?\n *\n * It is not part of special characters for the query syntax in the Lucene.\n *\n * Relevant links:\n * https://lucene.apache.org/core/3_4_0/queryparsersyntax.html\n * https://discuss.elastic.co/t/special-characters-in-field-names/10658/3\n * https://discuss.elastic.co/t/illegal-characters-in-elasticsearch-field-names/17196/2\n */\n const isLocked = lockedFields.some(lockedField => {\n return lockedField.fieldId === field.storageId || lockedField.fieldId === field.fieldId;\n });\n if (!field.storageId) {\n /**\n * In case field is locked, we must set the storageId to the fieldId value.\n * This should not happen, because we upgrade all the fields in 5.33.0, but let's have a check just in case of some upgrade miss.\n */\n //\n if (isLocked) {\n field.storageId = field.fieldId;\n }\n /**\n * When having original field, just set the storageId to value from the originalField\n */\n //\n else if (originalField) {\n field.storageId = originalField.storageId;\n }\n /**\n * The last case is when no original field and not locked - so this is a completely new field.\n */\n //\n else {\n field.storageId = createFieldStorageId(field);\n }\n }\n /**\n * Check the field's fieldId against existing ones.\n * There cannot be two fields with the same fieldId - outside world identifier.\n */\n if (fieldIdList.includes(field.fieldId)) {\n throw new WebinyError(\n `Cannot update content model because field \"${field.storageId}\" has fieldId \"${field.fieldId}\", which is already used.`\n );\n }\n fieldIdList.push(field.fieldId);\n /**\n * Check the field's storageId against the existing ones.\n * There cannot be two fields with the same storageId.\n */\n if (storageIdList.includes(field.storageId)) {\n throw new WebinyError(\n `Cannot update content model because field \"${field.label}\" has storageId \"${field.storageId}\", which is already used.`\n );\n }\n storageIdList.push(field.storageId);\n /**\n * There might be some plugins which allow child fields.\n * We use this method to validate them as well.\n */\n if (!plugin.validateChildFields) {\n continue;\n }\n const validateChildFields = createValidateChildFields(plugins);\n plugin.validateChildFields({\n field,\n originalField,\n validate: validateChildFields\n });\n }\n};\n\ninterface CreateGraphQLSchemaParams {\n context: CmsContext;\n model: CmsModel;\n}\n\nconst createGraphQLSchema = async (params: CreateGraphQLSchemaParams): Promise<any> => {\n const { context, model } = params;\n\n const models = await context.security.withoutAuthorization(async () => {\n return (await context.cms.listModels()).filter((model): model is CmsModel => {\n return model.isPrivate !== true;\n });\n });\n\n const modelPlugins = await buildSchemaPlugins({\n context,\n models: models.concat([model])\n });\n\n const plugins = context.plugins\n .byType<CmsGraphQLSchemaPlugin>(CmsGraphQLSchemaPlugin.type)\n .reduce<Record<string, CmsGraphQLSchemaPlugin>>((collection, plugin) => {\n const name =\n plugin.name || `${CmsGraphQLSchemaPlugin.type}-${generateAlphaNumericId(16)}`;\n collection[name] = plugin;\n return collection;\n }, {});\n for (const plugin of modelPlugins) {\n const name = plugin.name || `${plugin.type}-${generateAlphaNumericId(16)}`;\n plugins[name] = plugin;\n }\n\n return createExecutableSchema({\n plugins: Object.values(plugins)\n });\n};\n\nconst extractErrorObject = (error: any) => {\n return [\"message\", \"code\", \"data\", \"stack\"].reduce<Record<string, any>>((output, key) => {\n if (!error[key]) {\n return output;\n }\n output[key] = error[key];\n return output;\n }, {});\n};\n\ninterface ValidateModelFieldsParams {\n models: CmsModel[];\n model: CmsModel;\n original?: CmsModel;\n context: CmsContext;\n}\n\nexport const validateModelFields = async (params: ValidateModelFieldsParams): Promise<void> => {\n const { models, model, original, context } = params;\n const { titleFieldId, descriptionFieldId, imageFieldId } = model;\n const { plugins } = context;\n\n /**\n * There should be fields/locked fields in either model or data to be updated.\n */\n const { fields = [], lockedFields = [] } = model;\n\n /**\n * Let's inspect the fields of the received content model. We prevent saving of a content model if it\n * contains a field for which a \"cms-model-field-to-graphql\" plugin does not exist on the backend.\n */\n const fieldTypePlugins = plugins.byType<CmsModelFieldToGraphQLPlugin>(\n \"cms-model-field-to-graphql\"\n );\n\n validateFields({\n fields,\n originalFields: original?.fields || [],\n lockedFields,\n plugins: fieldTypePlugins\n });\n\n if (fields.length) {\n const sorterPlugins = plugins.byType<CmsGraphQLSchemaSorterPlugin>(\n CmsGraphQLSchemaSorterPlugin.type\n );\n /**\n * Make sure that this model can be safely converted to a GraphQL SDL\n */\n const schema = createManageSDL({\n models,\n model,\n fieldTypePlugins: fieldTypePlugins.reduce(\n (acc, pl) => ({ ...acc, [pl.fieldType]: pl }),\n {}\n ),\n sorterPlugins\n });\n\n try {\n gql(schema);\n } catch (err) {\n throw new WebinyError(extractInvalidField(model, err));\n }\n /**\n *\n */\n try {\n await createGraphQLSchema({\n context,\n model\n });\n } catch (err) {\n throw new WebinyError({\n message:\n \"Cannot generate GraphQL schema when testing with the given model. Please check the response for more details.\",\n code: \"GRAPHQL_SCHEMA_ERROR\",\n data: {\n modelId: model.modelId,\n error: extractErrorObject(err)\n }\n });\n }\n }\n\n model.titleFieldId = getContentModelTitleFieldId(fields, titleFieldId);\n model.descriptionFieldId = getContentModelDescriptionFieldId(fields, descriptionFieldId);\n model.imageFieldId = getContentModelImageFieldId(fields, imageFieldId);\n\n const cmsLockedFieldPlugins =\n plugins.byType<CmsModelLockedFieldPlugin>(\"cms-model-locked-field\");\n\n /**\n * We must not allow removal or changes in fields that are already in use in content entries.\n * Locked fields still have fieldId (should be storageId) because of the old existing locked fields in the models.\n */\n for (const lockedField of lockedFields) {\n const existingField = fields.find(item => item.storageId === lockedField.fieldId);\n\n /**\n * Starting with 5.33.0 fields can be deleted.\n * Our UI gives a warning upon locked field deletion, but if user is managing fields through API directly - we cannot do anything.\n */\n if (!existingField) {\n continue;\n }\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 reason: `\"multipleValues\" changed`,\n field: existingField\n }\n );\n }\n\n const fieldType = getBaseFieldType(existingField);\n if (lockedField.type !== fieldType) {\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 reason: `\"type\" changed`,\n lockedFieldType: lockedField.type,\n existingFieldType: fieldType\n }\n );\n }\n\n /**\n * Check `lockedField` invariant for specific field\n */\n const lockedFieldsByType = cmsLockedFieldPlugins.filter(\n pl => pl.fieldType === getBaseFieldType(lockedField)\n );\n for (const plugin of lockedFieldsByType) {\n if (typeof plugin.checkLockedField !== \"function\") {\n continue;\n }\n plugin.checkLockedField({\n lockedField,\n field: existingField\n });\n }\n }\n};\n"],"mappings":";;;;;;;;AAAA;AACA;AAUA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,MAAMA,mBAAmB,GAAG,CAACC,KAAe,EAAEC,GAAiB,KAAK;EAAA;EAChE,MAAMC,GAAG,GAAG,gBAAAD,GAAG,CAACE,MAAM,gDAAV,YAAYC,IAAI,KAAI,EAAE;;EAElC;AACJ;AACA;EACI,MAAM;IAAEC,IAAI,EAAEC;EAAW,CAAC,GAAGL,GAAG,CAACM,SAAS,GACpCN,GAAG,CAACM,SAAS,CAAC,CAAC,CAAC,GAChB;IACIF,IAAI,EAAE;EACV,CAAC;EACP,MAAMG,QAAQ,GAAGN,GAAG,CAACO,KAAK,CAAC,IAAI,CAAC;EAChC,IAAIC,OAAO;EACX,IAAIC,OAAO;EACX,KAAK,IAAIC,CAAC,GAAGN,UAAU,EAAEM,CAAC,GAAG,CAAC,EAAEA,CAAC,EAAE,EAAE;IACjC,IAAIF,OAAO,IAAIA,OAAO,CAACG,QAAQ,CAAC,OAAO,CAAC,EAAE;MACtCF,OAAO,GAAGD,OAAO,CAACI,KAAK,CAAC,kBAAkB,CAAC;MAC3C;IACJ;IAEAJ,OAAO,GAAGF,QAAQ,CAACI,CAAC,CAAC;EACzB;EAEA,IAAIG,YAAgC,GAAGC,SAAS;EAChD,IAAIC,KAAK,CAACC,OAAO,CAACP,OAAO,CAAC,EAAE;IACxB,MAAMQ,UAAU,GAAG,IAAIC,MAAM,CAAE,wBAAuBT,OAAO,CAAC,CAAC,CAAE,QAAO,CAAC;IAEzE,MAAMU,OAAO,GAAGnB,GAAG,CAACY,KAAK,CAACK,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