@webiny/api-headless-cms 5.34.3-beta.1 → 5.34.3-beta.3

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 (51) hide show
  1. package/crud/contentModel/beforeCreate.d.ts +2 -3
  2. package/crud/contentModel/beforeCreate.js +4 -4
  3. package/crud/contentModel/beforeCreate.js.map +1 -1
  4. package/crud/contentModel/beforeUpdate.d.ts +2 -4
  5. package/crud/contentModel/beforeUpdate.js +2 -2
  6. package/crud/contentModel/beforeUpdate.js.map +1 -1
  7. package/crud/contentModel/validateModel.d.ts +3 -4
  8. package/crud/contentModel/validateModel.js +6 -3
  9. package/crud/contentModel/validateModel.js.map +1 -1
  10. package/crud/contentModel/validateModelFields.d.ts +3 -4
  11. package/crud/contentModel/validateModelFields.js +74 -6
  12. package/crud/contentModel/validateModelFields.js.map +1 -1
  13. package/crud/contentModel.crud.js +3 -18
  14. package/crud/contentModel.crud.js.map +1 -1
  15. package/graphql/buildSchemaPlugins.d.ts +7 -2
  16. package/graphql/buildSchemaPlugins.js +3 -6
  17. package/graphql/buildSchemaPlugins.js.map +1 -1
  18. package/graphql/createExecutableSchema.d.ts +7 -0
  19. package/graphql/createExecutableSchema.js +33 -0
  20. package/graphql/createExecutableSchema.js.map +1 -0
  21. package/graphql/generateSchema.d.ts +8 -0
  22. package/graphql/generateSchema.js +38 -0
  23. package/graphql/generateSchema.js.map +1 -0
  24. package/graphql/graphQLHandlerFactory.js +11 -34
  25. package/graphql/graphQLHandlerFactory.js.map +1 -1
  26. package/graphql/index.d.ts +1 -3
  27. package/graphql/index.js +2 -41
  28. package/graphql/index.js.map +1 -1
  29. package/graphql/schema/baseContentSchema.d.ts +5 -1
  30. package/graphql/schema/baseContentSchema.js +3 -1
  31. package/graphql/schema/baseContentSchema.js.map +1 -1
  32. package/graphql/schema/baseSchema.d.ts +3 -0
  33. package/graphql/schema/baseSchema.js +58 -0
  34. package/graphql/schema/baseSchema.js.map +1 -0
  35. package/graphql/schema/contentEntries.d.ts +5 -1
  36. package/graphql/schema/contentEntries.js +3 -1
  37. package/graphql/schema/contentEntries.js.map +1 -1
  38. package/graphql/schema/contentModelGroups.d.ts +5 -1
  39. package/graphql/schema/contentModelGroups.js +3 -1
  40. package/graphql/schema/contentModelGroups.js.map +1 -1
  41. package/graphql/schema/contentModels.d.ts +5 -1
  42. package/graphql/schema/contentModels.js +3 -1
  43. package/graphql/schema/contentModels.js.map +1 -1
  44. package/graphql/schema/schemaPlugins.d.ts +7 -2
  45. package/graphql/schema/schemaPlugins.js +45 -43
  46. package/graphql/schema/schemaPlugins.js.map +1 -1
  47. package/index.d.ts +1 -1
  48. package/package.json +23 -23
  49. package/utils/filterModelFields.d.ts +0 -16
  50. package/utils/filterModelFields.js +0 -77
  51. package/utils/filterModelFields.js.map +0 -1
@@ -1,11 +1,10 @@
1
- import { OnModelBeforeCreateFromTopicParams, OnModelBeforeCreateTopicParams, HeadlessCmsStorageOperations } from "../../types";
1
+ import { OnModelBeforeCreateFromTopicParams, OnModelBeforeCreateTopicParams, HeadlessCmsStorageOperations, CmsContext } from "../../types";
2
2
  import { Topic } from "@webiny/pubsub/types";
3
- import { PluginsContainer } from "@webiny/plugins";
4
3
  interface AssignBeforeModelCreateParams {
5
4
  onModelBeforeCreate: Topic<OnModelBeforeCreateTopicParams>;
6
5
  onModelBeforeCreateFrom: Topic<OnModelBeforeCreateFromTopicParams>;
7
6
  storageOperations: HeadlessCmsStorageOperations;
8
- plugins: PluginsContainer;
7
+ context: CmsContext;
9
8
  }
10
9
  /**
11
10
  * We attach both on before create and createFrom events here.
@@ -154,7 +154,7 @@ const assignModelBeforeCreate = params => {
154
154
  onModelBeforeCreate,
155
155
  onModelBeforeCreateFrom,
156
156
  storageOperations,
157
- plugins
157
+ context
158
158
  } = params;
159
159
  onModelBeforeCreate.subscribe(async ({
160
160
  model,
@@ -170,7 +170,7 @@ const assignModelBeforeCreate = params => {
170
170
 
171
171
  const cb = createOnModelBeforeCb({
172
172
  storageOperations,
173
- plugins
173
+ plugins: context.plugins
174
174
  });
175
175
  await cb({
176
176
  model,
@@ -182,12 +182,12 @@ const assignModelBeforeCreate = params => {
182
182
 
183
183
  await (0, _validateModel.validateModel)({
184
184
  model,
185
- plugins
185
+ context
186
186
  });
187
187
  });
188
188
  onModelBeforeCreateFrom.subscribe(createOnModelBeforeCb({
189
189
  storageOperations,
190
- plugins
190
+ plugins: context.plugins
191
191
  }));
192
192
  };
193
193
 
@@ -1 +1 @@
1
- {"version":3,"names":["disallowedModelIdList","disallowedModelIdEndingList","checkModelIdUniqueness","modelIdList","modelId","includes","WebinyError","pluralizedModelIdCamelCase","pluralize","plural","singularizedModelIdCamelCase","singular","checkModelIdAllowed","checkModelIdEndingAllowed","ending","re","RegExp","matched","match","getModelId","model","name","camelCase","trim","createOnModelBeforeCb","plugins","storageOperations","params","modelPlugin","byType","CmsModelPlugin","type","find","item","contentModel","models","list","where","tenant","locale","map","m","assignModelBeforeCreate","onModelBeforeCreate","onModelBeforeCreateFrom","subscribe","input","validateLayout","layout","fields","cb","validateModel"],"sources":["beforeCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport camelCase from \"lodash/camelCase\";\nimport pluralize from \"pluralize\";\nimport {\n OnModelBeforeCreateFromTopicParams,\n OnModelBeforeCreateTopicParams,\n CmsModel,\n HeadlessCmsStorageOperations\n} from \"~/types\";\nimport { Topic } from \"@webiny/pubsub/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsModelPlugin } from \"~/plugins/CmsModelPlugin\";\nimport { validateModel } from \"./validateModel\";\nimport { validateLayout } from \"./validateLayout\";\n\nconst disallowedModelIdList: string[] = [\n \"contentModel\",\n \"contentModels\",\n \"contentModelGroup\",\n \"contentModelGroups\"\n];\n/**\n * This list is to disallow creating models that might interfere with GraphQL schema creation.\n * Add more if required.\n */\nconst disallowedModelIdEndingList: string[] = [\n \"Response\",\n \"List\",\n \"Meta\",\n \"Input\",\n \"Sorter\",\n \"RefType\"\n];\n\n/**\n * Checks for the uniqueness of provided modelId, against the provided list of models.\n * It also takes plural / singular forms of the provided modelId into account.\n */\nconst checkModelIdUniqueness = (modelIdList: string[], modelId: string) => {\n if (modelIdList.includes(modelId) === true) {\n throw new WebinyError(\n `Content model with modelId \"${modelId}\" already exists.`,\n \"MODEL_ID_EXISTS\",\n {\n modelId\n }\n );\n }\n /**\n * Additionally, check if the plural form of the received modelId exists too. This prevents users\n * from creating, for example, \"event\" and \"events\" models, which would break the GraphQL schema.\n * 1. First check if user wants to create the \"event\" model, but the \"events\" model already exists.\n */\n const pluralizedModelIdCamelCase = pluralize(modelId);\n if (modelIdList.includes(pluralizedModelIdCamelCase) === true) {\n throw new WebinyError(\n `Content model with modelId \"${modelId}\" does not exist, but a model with modelId \"${pluralizedModelIdCamelCase}\" does.`,\n \"MODEL_ID_PLURAL_ERROR\",\n {\n modelId,\n plural: pluralizedModelIdCamelCase\n }\n );\n }\n\n /**\n * 2. Then check if user wants to create the \"events\" model, but the \"event\" model already exists.\n */\n const singularizedModelIdCamelCase = pluralize.singular(modelId);\n if (modelIdList.includes(singularizedModelIdCamelCase) === true) {\n throw new WebinyError(\n `Content model with modelId \"${modelId}\" does not exist, but a model with modelId \"${singularizedModelIdCamelCase}\" does.`,\n \"MODEL_ID_SINGULAR_ERROR\",\n {\n modelId,\n singular: singularizedModelIdCamelCase\n }\n );\n }\n};\n\nconst checkModelIdAllowed = (modelId: string): void => {\n if (disallowedModelIdList.includes(modelId) === false) {\n return;\n }\n throw new WebinyError(`Provided model ID \"${modelId}\" is not allowed.`);\n};\n\nconst checkModelIdEndingAllowed = (modelId: string): void => {\n for (const ending of disallowedModelIdEndingList) {\n const re = new RegExp(`${ending}$`, \"i\");\n const matched = modelId.match(re);\n if (matched === null) {\n continue;\n }\n throw new WebinyError(\n `ModelId that ends with \"${ending}\" is not allowed.`,\n \"MODEL_ID_NOT_ALLOWED\",\n {\n modelId\n }\n );\n }\n};\n\nconst getModelId = (model: CmsModel): string => {\n const { modelId, name } = model;\n if (!!modelId) {\n return camelCase(modelId.trim());\n } else if (name) {\n return camelCase(name.trim());\n }\n throw new WebinyError(\n `There is no \"modelId\" or \"name\" passed into the create model method.`,\n \"MISSING_MODEL_DATA\",\n {\n model\n }\n );\n};\n\ninterface CreateOnModelBeforeCreateCbParams {\n plugins: PluginsContainer;\n storageOperations: HeadlessCmsStorageOperations;\n}\nconst createOnModelBeforeCb = ({\n plugins,\n storageOperations\n}: CreateOnModelBeforeCreateCbParams) => {\n return async (params: OnModelBeforeCreateTopicParams | OnModelBeforeCreateFromTopicParams) => {\n const { model } = params;\n\n const modelId = getModelId(model);\n\n const modelPlugin = plugins\n .byType<CmsModelPlugin>(CmsModelPlugin.type)\n .find((item: CmsModelPlugin) => item.contentModel.modelId === modelId);\n\n if (modelPlugin) {\n throw new WebinyError(\n `Cannot create \"${model.modelId}\" content model because one is already registered via a plugin.`,\n \"CONTENT_MODEL_CREATE_ERROR\",\n {\n modelId: model.modelId\n }\n );\n }\n\n const models = await storageOperations.models.list({\n where: {\n tenant: model.tenant,\n locale: model.locale\n }\n });\n const modelIdList = models.map(m => m.modelId);\n\n /**\n * We need to check for:\n * - is that exact modelId allowed\n * - is modelId unique\n * - is model ending allowed\n */\n checkModelIdAllowed(modelId);\n checkModelIdEndingAllowed(modelId);\n checkModelIdUniqueness(modelIdList, modelId);\n model.modelId = modelId;\n };\n};\n\ninterface AssignBeforeModelCreateParams {\n onModelBeforeCreate: Topic<OnModelBeforeCreateTopicParams>;\n onModelBeforeCreateFrom: Topic<OnModelBeforeCreateFromTopicParams>;\n storageOperations: HeadlessCmsStorageOperations;\n plugins: PluginsContainer;\n}\n\n/**\n * We attach both on before create and createFrom events here.\n * Callables are identical.\n */\nexport const assignModelBeforeCreate = (params: AssignBeforeModelCreateParams) => {\n const { onModelBeforeCreate, onModelBeforeCreateFrom, storageOperations, plugins } = params;\n\n onModelBeforeCreate.subscribe(async ({ model, input }) => {\n /**\n * First the layout...\n */\n validateLayout(model.layout, model.fields);\n /**\n * then we run the shared create/createFrom methods.\n */\n const cb = createOnModelBeforeCb({\n storageOperations,\n plugins\n });\n await cb({\n model,\n input\n });\n\n /**\n * and then we move onto model and fields...\n */\n await validateModel({\n model,\n plugins\n });\n });\n\n onModelBeforeCreateFrom.subscribe(\n createOnModelBeforeCb({\n storageOperations,\n plugins\n })\n );\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AASA;;AACA;;AACA;;AAEA,MAAMA,qBAA+B,GAAG,CACpC,cADoC,EAEpC,eAFoC,EAGpC,mBAHoC,EAIpC,oBAJoC,CAAxC;AAMA;AACA;AACA;AACA;;AACA,MAAMC,2BAAqC,GAAG,CAC1C,UAD0C,EAE1C,MAF0C,EAG1C,MAH0C,EAI1C,OAJ0C,EAK1C,QAL0C,EAM1C,SAN0C,CAA9C;AASA;AACA;AACA;AACA;;AACA,MAAMC,sBAAsB,GAAG,CAACC,WAAD,EAAwBC,OAAxB,KAA4C;EACvE,IAAID,WAAW,CAACE,QAAZ,CAAqBD,OAArB,MAAkC,IAAtC,EAA4C;IACxC,MAAM,IAAIE,cAAJ,CACD,+BAA8BF,OAAQ,mBADrC,EAEF,iBAFE,EAGF;MACIA;IADJ,CAHE,CAAN;EAOH;EACD;AACJ;AACA;AACA;AACA;;;EACI,MAAMG,0BAA0B,GAAG,IAAAC,kBAAA,EAAUJ,OAAV,CAAnC;;EACA,IAAID,WAAW,CAACE,QAAZ,CAAqBE,0BAArB,MAAqD,IAAzD,EAA+D;IAC3D,MAAM,IAAID,cAAJ,CACD,+BAA8BF,OAAQ,+CAA8CG,0BAA2B,SAD9G,EAEF,uBAFE,EAGF;MACIH,OADJ;MAEIK,MAAM,EAAEF;IAFZ,CAHE,CAAN;EAQH;EAED;AACJ;AACA;;;EACI,MAAMG,4BAA4B,GAAGF,kBAAA,CAAUG,QAAV,CAAmBP,OAAnB,CAArC;;EACA,IAAID,WAAW,CAACE,QAAZ,CA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zB,KAAF;IAAS0B;EAAT,CAAP,KAA4B;IACtD;AACR;AACA;IACQ,IAAAC,8BAAA,EAAe3B,KAAK,CAAC4B,MAArB,EAA6B5B,KAAK,CAAC6B,MAAnC;IACA;AACR;AACA;;IACQ,MAAMC,EAAE,GAAG1B,qBAAqB,CAAC;MAC7BE,iBAD6B;MAE7BD;IAF6B,CAAD,CAAhC;IAIA,MAAMyB,EAAE,CAAC;MACL9B,KADK;MAEL0B;IAFK,CAAD,CAAR;IAKA;AACR;AACA;;IACQ,MAAM,IAAAK,4BAAA,EAAc;MAChB/B,KADgB;MAEhBK;IAFgB,CAAd,CAAN;EAIH,CAxBD;EA0BAmB,uBAAuB,CAACC,SAAxB,CACIrB,qBAAqB,CAAC;IAClBE,iBADkB;IAElBD;EAFkB,CAAD,CADzB;AAMH,CAnCM"}
1
+ {"version":3,"names":["disallowedModelIdList","disallowedModelIdEndingList","checkModelIdUniqueness","modelIdList","modelId","includes","WebinyError","pluralizedModelIdCamelCase","pluralize","plural","singularizedModelIdCamelCase","singular","checkModelIdAllowed","checkModelIdEndingAllowed","ending","re","RegExp","matched","match","getModelId","model","name","camelCase","trim","createOnModelBeforeCb","plugins","storageOperations","params","modelPlugin","byType","CmsModelPlugin","type","find","item","contentModel","models","list","where","tenant","locale","map","m","assignModelBeforeCreate","onModelBeforeCreate","onModelBeforeCreateFrom","context","subscribe","input","validateLayout","layout","fields","cb","validateModel"],"sources":["beforeCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport camelCase from \"lodash/camelCase\";\nimport pluralize from \"pluralize\";\nimport {\n OnModelBeforeCreateFromTopicParams,\n OnModelBeforeCreateTopicParams,\n CmsModel,\n HeadlessCmsStorageOperations,\n CmsContext\n} from \"~/types\";\nimport { Topic } from \"@webiny/pubsub/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsModelPlugin } from \"~/plugins/CmsModelPlugin\";\nimport { validateModel } from \"./validateModel\";\nimport { validateLayout } from \"./validateLayout\";\n\nconst disallowedModelIdList: string[] = [\n \"contentModel\",\n \"contentModels\",\n \"contentModelGroup\",\n \"contentModelGroups\"\n];\n/**\n * This list is to disallow creating models that might interfere with GraphQL schema creation.\n * Add more if required.\n */\nconst disallowedModelIdEndingList: string[] = [\n \"Response\",\n \"List\",\n \"Meta\",\n \"Input\",\n \"Sorter\",\n \"RefType\"\n];\n\n/**\n * Checks for the uniqueness of provided modelId, against the provided list of models.\n * It also takes plural / singular forms of the provided modelId into account.\n */\nconst checkModelIdUniqueness = (modelIdList: string[], modelId: string) => {\n if (modelIdList.includes(modelId) === true) {\n throw new WebinyError(\n `Content model with modelId \"${modelId}\" already exists.`,\n \"MODEL_ID_EXISTS\",\n {\n modelId\n }\n );\n }\n /**\n * Additionally, check if the plural form of the received modelId exists too. This prevents users\n * from creating, for example, \"event\" and \"events\" models, which would break the GraphQL schema.\n * 1. First check if user wants to create the \"event\" model, but the \"events\" model already exists.\n */\n const pluralizedModelIdCamelCase = pluralize(modelId);\n if (modelIdList.includes(pluralizedModelIdCamelCase) === true) {\n throw new WebinyError(\n `Content model with modelId \"${modelId}\" does not exist, but a model with modelId \"${pluralizedModelIdCamelCase}\" does.`,\n \"MODEL_ID_PLURAL_ERROR\",\n {\n modelId,\n plural: pluralizedModelIdCamelCase\n }\n );\n }\n\n /**\n * 2. Then check if user wants to create the \"events\" model, but the \"event\" model already exists.\n */\n const singularizedModelIdCamelCase = pluralize.singular(modelId);\n if (modelIdList.includes(singularizedModelIdCamelCase) === true) {\n throw new WebinyError(\n `Content model with modelId \"${modelId}\" does not exist, but a model with modelId \"${singularizedModelIdCamelCase}\" does.`,\n \"MODEL_ID_SINGULAR_ERROR\",\n {\n modelId,\n singular: singularizedModelIdCamelCase\n }\n );\n }\n};\n\nconst checkModelIdAllowed = (modelId: string): void => {\n if (disallowedModelIdList.includes(modelId) === false) {\n return;\n }\n throw new WebinyError(`Provided model ID \"${modelId}\" is not allowed.`);\n};\n\nconst checkModelIdEndingAllowed = (modelId: string): void => {\n for (const ending of disallowedModelIdEndingList) {\n const re = new RegExp(`${ending}$`, \"i\");\n const matched = modelId.match(re);\n if (matched === null) {\n continue;\n }\n throw new WebinyError(\n `ModelId that ends with \"${ending}\" is not allowed.`,\n \"MODEL_ID_NOT_ALLOWED\",\n {\n modelId\n }\n );\n }\n};\n\nconst getModelId = (model: CmsModel): string => {\n const { modelId, name } = model;\n if (!!modelId) {\n return camelCase(modelId.trim());\n } else if (name) {\n return camelCase(name.trim());\n }\n throw new WebinyError(\n `There is no \"modelId\" or \"name\" passed into the create model method.`,\n \"MISSING_MODEL_DATA\",\n {\n model\n }\n );\n};\n\ninterface CreateOnModelBeforeCreateCbParams {\n plugins: PluginsContainer;\n storageOperations: HeadlessCmsStorageOperations;\n}\nconst createOnModelBeforeCb = ({\n plugins,\n storageOperations\n}: CreateOnModelBeforeCreateCbParams) => {\n return async (params: OnModelBeforeCreateTopicParams | OnModelBeforeCreateFromTopicParams) => {\n const { model } = params;\n\n const modelId = getModelId(model);\n\n const modelPlugin = plugins\n .byType<CmsModelPlugin>(CmsModelPlugin.type)\n .find((item: CmsModelPlugin) => item.contentModel.modelId === modelId);\n\n if (modelPlugin) {\n throw new WebinyError(\n `Cannot create \"${model.modelId}\" content model because one is already registered via a plugin.`,\n \"CONTENT_MODEL_CREATE_ERROR\",\n {\n modelId: model.modelId\n }\n );\n }\n\n const models = await storageOperations.models.list({\n where: {\n tenant: model.tenant,\n locale: model.locale\n }\n });\n const modelIdList = models.map(m => m.modelId);\n\n /**\n * We need to check for:\n * - is that exact modelId allowed\n * - is modelId unique\n * - is model ending allowed\n */\n checkModelIdAllowed(modelId);\n checkModelIdEndingAllowed(modelId);\n checkModelIdUniqueness(modelIdList, modelId);\n model.modelId = modelId;\n };\n};\n\ninterface AssignBeforeModelCreateParams {\n onModelBeforeCreate: Topic<OnModelBeforeCreateTopicParams>;\n onModelBeforeCreateFrom: Topic<OnModelBeforeCreateFromTopicParams>;\n storageOperations: HeadlessCmsStorageOperations;\n context: CmsContext;\n}\n\n/**\n * We attach both on before create and createFrom events here.\n * Callables are identical.\n */\nexport const assignModelBeforeCreate = (params: AssignBeforeModelCreateParams) => {\n const { onModelBeforeCreate, onModelBeforeCreateFrom, storageOperations, context } = params;\n\n onModelBeforeCreate.subscribe(async ({ model, input }) => {\n /**\n * First the layout...\n */\n validateLayout(model.layout, model.fields);\n /**\n * then we run the shared create/createFrom methods.\n */\n const cb = createOnModelBeforeCb({\n storageOperations,\n plugins: context.plugins\n });\n await cb({\n model,\n input\n });\n /**\n * and then we move onto model and fields...\n */\n await validateModel({\n model,\n context\n });\n });\n\n onModelBeforeCreateFrom.subscribe(\n createOnModelBeforeCb({\n storageOperations,\n plugins: context.plugins\n })\n );\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAUA;;AACA;;AACA;;AAEA,MAAMA,qBAA+B,GAAG,CACpC,cADoC,EAEpC,eAFoC,EAGpC,mBAHoC,EAIpC,oBAJoC,CAAxC;AAMA;AACA;AACA;AACA;;AACA,MAAMC,2BAAqC,GAAG,CAC1C,UAD0C,EAE1C,MAF0C,EAG1C,MAH0C,EAI1C,OAJ0C,EAK1C,QAL0C,EAM1C,SAN0C,CAA9C;AASA;AACA;AACA;AACA;;AACA,MAAMC,sBAAsB,GAAG,CAACC,WAAD,EAAwBC,OAAxB,KAA4C;EACvE,IAAID,WAAW,CAACE,QAAZ,CAAqBD,OAArB,MAAkC,IAAtC,EAA4C;IACxC,MAAM,IAAIE,cAAJ,CACD,+BAA8BF,OAAQ,mBADrC,EAEF,iBAFE,EAGF;MACIA;IADJ,CAHE,CAAN;EAOH;EACD;AACJ;AACA;AACA;AACA;;;EACI,MAAMG,0BAA0B,GAAG,IAAAC,kBAAA,EAAUJ,OAAV,CAAnC;;EACA,IAAID,WAAW,CAACE,QAAZ,CAAqBE,0BAArB,MAAqD,IAAzD,EAA+D;IAC3D,MAAM,IAAID,cAAJ,CACD,+BAA8BF,OAAQ,+CAA8CG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CH,CA1CD;;AAmDA;AACA;AACA;AACA;AACO,MAAMsC,uBAAuB,GAAIf,MAAD,IAA2C;EAC9E,MAAM;IAAEgB,mBAAF;IAAuBC,uBAAvB;IAAgDlB,iBAAhD;IAAmEmB;EAAnE,IAA+ElB,MAArF;EAEAgB,mBAAmB,CAACG,SAApB,CAA8B,OAAO;IAAE1B,KAAF;IAAS2B;EAAT,CAAP,KAA4B;IACtD;AACR;AACA;IACQ,IAAAC,8BAAA,EAAe5B,KAAK,CAAC6B,MAArB,EAA6B7B,KAAK,CAAC8B,MAAnC;IACA;AACR;AACA;;IACQ,MAAMC,EAAE,GAAG3B,qBAAqB,CAAC;MAC7BE,iBAD6B;MAE7BD,OAAO,EAAEoB,OAAO,CAACpB;IAFY,CAAD,CAAhC;IAIA,MAAM0B,EAAE,CAAC;MACL/B,KADK;MAEL2B;IAFK,CAAD,CAAR;IAIA;AACR;AACA;;IACQ,MAAM,IAAAK,4BAAA,EAAc;MAChBhC,KADgB;MAEhByB;IAFgB,CAAd,CAAN;EAIH,CAvBD;EAyBAD,uBAAuB,CAACE,SAAxB,CACItB,qBAAqB,CAAC;IAClBE,iBADkB;IAElBD,OAAO,EAAEoB,OAAO,CAACpB;EAFC,CAAD,CADzB;AAMH,CAlCM"}
@@ -1,10 +1,8 @@
1
1
  import { Topic } from "@webiny/pubsub/types";
2
- import { OnModelBeforeUpdateTopicParams, HeadlessCmsStorageOperations } from "../../types";
3
- import { PluginsContainer } from "@webiny/plugins";
2
+ import { OnModelBeforeUpdateTopicParams, CmsContext } from "../../types";
4
3
  interface AssignBeforeModelUpdateParams {
5
4
  onModelBeforeUpdate: Topic<OnModelBeforeUpdateTopicParams>;
6
- storageOperations: HeadlessCmsStorageOperations;
7
- plugins: PluginsContainer;
5
+ context: CmsContext;
8
6
  }
9
7
  export declare const assignModelBeforeUpdate: (params: AssignBeforeModelUpdateParams) => void;
10
8
  export {};
@@ -12,7 +12,7 @@ var _validateLayout = require("./validateLayout");
12
12
  const assignModelBeforeUpdate = params => {
13
13
  const {
14
14
  onModelBeforeUpdate,
15
- plugins
15
+ context
16
16
  } = params;
17
17
  onModelBeforeUpdate.subscribe(async ({
18
18
  model,
@@ -29,7 +29,7 @@ const assignModelBeforeUpdate = params => {
29
29
  await (0, _validateModel.validateModel)({
30
30
  model,
31
31
  original,
32
- plugins
32
+ context
33
33
  });
34
34
  });
35
35
  };
@@ -1 +1 @@
1
- {"version":3,"names":["assignModelBeforeUpdate","params","onModelBeforeUpdate","plugins","subscribe","model","original","validateLayout","layout","fields","validateModel"],"sources":["beforeUpdate.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { OnModelBeforeUpdateTopicParams, HeadlessCmsStorageOperations } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { validateModel } from \"./validateModel\";\nimport { validateLayout } from \"./validateLayout\";\n\ninterface AssignBeforeModelUpdateParams {\n onModelBeforeUpdate: Topic<OnModelBeforeUpdateTopicParams>;\n storageOperations: HeadlessCmsStorageOperations;\n plugins: PluginsContainer;\n}\n\nexport const assignModelBeforeUpdate = (params: AssignBeforeModelUpdateParams) => {\n const { onModelBeforeUpdate, plugins } = 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 plugins\n });\n });\n};\n"],"mappings":";;;;;;;AAGA;;AACA;;AAQO,MAAMA,uBAAuB,GAAIC,MAAD,IAA2C;EAC9E,MAAM;IAAEC,mBAAF;IAAuBC;EAAvB,IAAmCF,MAAzC;EAEAC,mBAAmB,CAACE,SAApB,CAA8B,OAAO;IAAEC,KAAF;IAASC;EAAT,CAAP,KAA+B;IACzD;AACR;AACA;IACQ,IAAAC,8BAAA,EAAeF,KAAK,CAACG,MAArB,EAA6BH,KAAK,CAACI,MAAnC;IACA;AACR;AACA;;IACQ,MAAM,IAAAC,4BAAA,EAAc;MAChBL,KADgB;MAEhBC,QAFgB;MAGhBH;IAHgB,CAAd,CAAN;EAKH,CAbD;AAcH,CAjBM"}
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,MAAD,IAA2C;EAC9E,MAAM;IAAEC,mBAAF;IAAuBC;EAAvB,IAAmCF,MAAzC;EAEAC,mBAAmB,CAACE,SAApB,CAA8B,OAAO;IAAEC,KAAF;IAASC;EAAT,CAAP,KAA+B;IACzD;AACR;AACA;IACQ,IAAAC,8BAAA,EAAeF,KAAK,CAACG,MAArB,EAA6BH,KAAK,CAACI,MAAnC;IACA;AACR;AACA;;IACQ,MAAM,IAAAC,4BAAA,EAAc;MAChBL,KADgB;MAEhBC,QAFgB;MAGhBH;IAHgB,CAAd,CAAN;EAKH,CAbD;AAcH,CAjBM"}
@@ -1,9 +1,8 @@
1
- import { CmsModel } from "../../types";
2
- import { PluginsContainer } from "@webiny/plugins";
1
+ import { CmsContext, CmsModel } from "../../types";
3
2
  interface ValidateModelParams {
4
3
  model: CmsModel;
5
4
  original?: CmsModel;
6
- plugins: PluginsContainer;
5
+ context: CmsContext;
7
6
  }
8
- export declare const validateModel: (params: ValidateModelParams) => void;
7
+ export declare const validateModel: (params: ValidateModelParams) => Promise<void>;
9
8
  export {};
@@ -13,11 +13,14 @@ var _CmsModelPlugin = require("../../plugins/CmsModelPlugin");
13
13
 
14
14
  var _validateModelFields = require("./validateModelFields");
15
15
 
16
- const validateModel = params => {
16
+ const validateModel = async params => {
17
17
  const {
18
18
  model,
19
- plugins
19
+ context
20
20
  } = params;
21
+ const {
22
+ plugins
23
+ } = context;
21
24
  const modelPlugin = plugins.byType(_CmsModelPlugin.CmsModelPlugin.type).find(item => item.contentModel.modelId === model.modelId);
22
25
 
23
26
  if (modelPlugin) {
@@ -26,7 +29,7 @@ const validateModel = params => {
26
29
  });
27
30
  }
28
31
 
29
- (0, _validateModelFields.validateModelFields)(params);
32
+ await (0, _validateModelFields.validateModelFields)(params);
30
33
  };
31
34
 
32
35
  exports.validateModel = validateModel;
@@ -1 +1 @@
1
- {"version":3,"names":["validateModel","params","model","plugins","modelPlugin","byType","CmsModelPlugin","type","find","item","contentModel","modelId","WebinyError","validateModelFields"],"sources":["validateModel.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsModelPlugin } from \"~/plugins/CmsModelPlugin\";\nimport { CmsModel } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { validateModelFields } from \"~/crud/contentModel/validateModelFields\";\n\ninterface ValidateModelParams {\n model: CmsModel;\n original?: CmsModel;\n plugins: PluginsContainer;\n}\n\nexport const validateModel = (params: ValidateModelParams) => {\n const { model, plugins } = params;\n\n const modelPlugin = plugins\n .byType<CmsModelPlugin>(CmsModelPlugin.type)\n .find(item => item.contentModel.modelId === model.modelId);\n\n if (modelPlugin) {\n throw new WebinyError(\n \"Content models defined via plugins cannot be updated.\",\n \"CONTENT_MODEL_UPDATE_ERROR\",\n {\n modelId: model.modelId\n }\n );\n }\n\n validateModelFields(params);\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AAGA;;AAQO,MAAMA,aAAa,GAAIC,MAAD,IAAiC;EAC1D,MAAM;IAAEC,KAAF;IAASC;EAAT,IAAqBF,MAA3B;EAEA,MAAMG,WAAW,GAAGD,OAAO,CACtBE,MADe,CACQC,8BAAA,CAAeC,IADvB,EAEfC,IAFe,CAEVC,IAAI,IAAIA,IAAI,CAACC,YAAL,CAAkBC,OAAlB,KAA8BT,KAAK,CAACS,OAFlC,CAApB;;EAIA,IAAIP,WAAJ,EAAiB;IACb,MAAM,IAAIQ,cAAJ,CACF,uDADE,EAEF,4BAFE,EAGF;MACID,OAAO,EAAET,KAAK,CAACS;IADnB,CAHE,CAAN;EAOH;;EAED,IAAAE,wCAAA,EAAoBZ,MAApB;AACH,CAlBM"}
1
+ {"version":3,"names":["validateModel","params","model","context","plugins","modelPlugin","byType","CmsModelPlugin","type","find","item","contentModel","modelId","WebinyError","validateModelFields"],"sources":["validateModel.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsModelPlugin } from \"~/plugins/CmsModelPlugin\";\nimport { CmsContext, CmsModel } from \"~/types\";\nimport { validateModelFields } from \"~/crud/contentModel/validateModelFields\";\n\ninterface ValidateModelParams {\n model: CmsModel;\n original?: CmsModel;\n context: CmsContext;\n}\n\nexport const validateModel = async (params: ValidateModelParams): Promise<void> => {\n const { model, context } = params;\n\n const { plugins } = context;\n\n const modelPlugin = plugins\n .byType<CmsModelPlugin>(CmsModelPlugin.type)\n .find(item => item.contentModel.modelId === model.modelId);\n\n if (modelPlugin) {\n throw new WebinyError(\n \"Content models defined via plugins cannot be updated.\",\n \"CONTENT_MODEL_UPDATE_ERROR\",\n {\n modelId: model.modelId\n }\n );\n }\n\n await validateModelFields(params);\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AAEA;;AAQO,MAAMA,aAAa,GAAG,MAAOC,MAAP,IAAsD;EAC/E,MAAM;IAAEC,KAAF;IAASC;EAAT,IAAqBF,MAA3B;EAEA,MAAM;IAAEG;EAAF,IAAcD,OAApB;EAEA,MAAME,WAAW,GAAGD,OAAO,CACtBE,MADe,CACQC,8BAAA,CAAeC,IADvB,EAEfC,IAFe,CAEVC,IAAI,IAAIA,IAAI,CAACC,YAAL,CAAkBC,OAAlB,KAA8BV,KAAK,CAACU,OAFlC,CAApB;;EAIA,IAAIP,WAAJ,EAAiB;IACb,MAAM,IAAIQ,cAAJ,CACF,uDADE,EAEF,4BAFE,EAGF;MACID,OAAO,EAAEV,KAAK,CAACU;IADnB,CAHE,CAAN;EAOH;;EAED,MAAM,IAAAE,wCAAA,EAAoBb,MAApB,CAAN;AACH,CApBM"}
@@ -1,9 +1,8 @@
1
- import { CmsModel } from "../../types";
2
- import { PluginsContainer } from "@webiny/plugins";
1
+ import { CmsContext, CmsModel } from "../../types";
3
2
  interface ValidateModelFieldsParams {
4
3
  model: CmsModel;
5
4
  original?: CmsModel;
6
- plugins: PluginsContainer;
5
+ context: CmsContext;
7
6
  }
8
- export declare const validateModelFields: (params: ValidateModelFieldsParams) => void;
7
+ export declare const validateModelFields: (params: ValidateModelFieldsParams) => Promise<void>;
9
8
  export {};
@@ -21,6 +21,12 @@ var _getBaseFieldType = require("../../utils/getBaseFieldType");
21
21
 
22
22
  var _plugins = require("../../plugins");
23
23
 
24
+ var _buildSchemaPlugins = require("../../graphql/buildSchemaPlugins");
25
+
26
+ var _createExecutableSchema = require("../../graphql/createExecutableSchema");
27
+
28
+ var _handlerGraphql = require("@webiny/handler-graphql");
29
+
24
30
  const defaultTitleFieldId = "id";
25
31
  const allowedTitleFieldTypes = ["text", "number"];
26
32
 
@@ -138,7 +144,7 @@ const createValidateChildFields = plugins => {
138
144
  fields,
139
145
  originalFields
140
146
  }) => {
141
- if (fields.length === 0) {
147
+ if (fields.length === 0 && originalFields.length === 0) {
142
148
  return;
143
149
  }
144
150
 
@@ -158,9 +164,9 @@ const validateFields = params => {
158
164
  originalFields,
159
165
  lockedFields
160
166
  } = params;
167
+ const idList = [];
161
168
  const fieldIdList = [];
162
169
  const storageIdList = [];
163
- const validateChildFields = createValidateChildFields(plugins);
164
170
 
165
171
  for (const field of fields) {
166
172
  const baseType = (0, _getBaseFieldType.getBaseFieldType)(field);
@@ -169,7 +175,17 @@ const validateFields = params => {
169
175
  if (!plugin) {
170
176
  throw new Error(`Cannot update content model because of the unknown "${baseType}" field.`);
171
177
  }
178
+ /**
179
+ * Check the field's id against existing ones.
180
+ * There cannot be two fields with the same id.
181
+ */
172
182
 
183
+
184
+ if (idList.includes(field.id)) {
185
+ throw new _error.default(`Cannot update content model because field "${field.storageId || field.fieldId}" has id "${field.id}", which is already used.`);
186
+ }
187
+
188
+ idList.push(field.id);
173
189
  const originalField = originalFields.find(f => f.id === field.id);
174
190
  /**
175
191
  * Field MUST have an fieldId defined.
@@ -196,7 +212,7 @@ const validateFields = params => {
196
212
 
197
213
 
198
214
  const isLocked = lockedFields.some(lockedField => {
199
- return lockedField.fieldId === field.storageId;
215
+ return lockedField.fieldId === field.storageId || lockedField.fieldId === field.fieldId;
200
216
  });
201
217
 
202
218
  if (!field.storageId) {
@@ -253,6 +269,7 @@ const validateFields = params => {
253
269
  continue;
254
270
  }
255
271
 
272
+ const validateChildFields = createValidateChildFields(plugins);
256
273
  plugin.validateChildFields({
257
274
  field,
258
275
  originalField,
@@ -261,15 +278,45 @@ const validateFields = params => {
261
278
  }
262
279
  };
263
280
 
264
- const validateModelFields = params => {
281
+ const createGraphQLSchema = async params => {
282
+ const {
283
+ context,
284
+ model
285
+ } = params;
286
+ const modelPlugins = await (0, _buildSchemaPlugins.buildSchemaPlugins)({
287
+ context,
288
+ models: [model]
289
+ });
290
+ const plugins = context.plugins.byType(_handlerGraphql.GraphQLSchemaPlugin.type);
291
+ plugins.push(...modelPlugins);
292
+ return (0, _createExecutableSchema.createExecutableSchema)({
293
+ plugins
294
+ });
295
+ };
296
+
297
+ const extractErrorObject = error => {
298
+ return ["message", "code", "data", "stack"].reduce((output, key) => {
299
+ if (!error[key]) {
300
+ return output;
301
+ }
302
+
303
+ output[key] = error[key];
304
+ return output;
305
+ }, {});
306
+ };
307
+
308
+ const validateModelFields = async params => {
265
309
  const {
266
310
  model,
267
311
  original,
268
- plugins
312
+ context
269
313
  } = params;
270
314
  const {
271
315
  titleFieldId
272
316
  } = model;
317
+ const {
318
+ plugins
319
+ } = context;
273
320
  /**
274
321
  * There should be fields/locked fields in either model or data to be updated.
275
322
  */
@@ -284,7 +331,6 @@ const validateModelFields = params => {
284
331
  */
285
332
 
286
333
  const fieldTypePlugins = plugins.byType("cms-model-field-to-graphql");
287
- const sorterPlugins = plugins.byType(_plugins.CmsGraphQLSchemaSorterPlugin.type);
288
334
  validateFields({
289
335
  fields,
290
336
  originalFields: (original === null || original === void 0 ? void 0 : original.fields) || [],
@@ -293,9 +339,11 @@ const validateModelFields = params => {
293
339
  });
294
340
 
295
341
  if (fields.length) {
342
+ const sorterPlugins = plugins.byType(_plugins.CmsGraphQLSchemaSorterPlugin.type);
296
343
  /**
297
344
  * Make sure that this model can be safely converted to a GraphQL SDL
298
345
  */
346
+
299
347
  const schema = (0, _createManageSDL.createManageSDL)({
300
348
  model,
301
349
  fieldTypePlugins: fieldTypePlugins.reduce((acc, pl) => (0, _objectSpread2.default)((0, _objectSpread2.default)({}, acc), {}, {
@@ -309,6 +357,26 @@ const validateModelFields = params => {
309
357
  } catch (err) {
310
358
  throw new _error.default(extractInvalidField(model, err));
311
359
  }
360
+ /**
361
+ *
362
+ */
363
+
364
+
365
+ try {
366
+ await createGraphQLSchema({
367
+ context,
368
+ model
369
+ });
370
+ } catch (err) {
371
+ throw new _error.default({
372
+ message: "Cannot generate GraphQL schema when testing with the given model. Please check the response for more details.",
373
+ code: "GRAPHQL_SCHEMA_ERROR",
374
+ data: {
375
+ modelId: model.modelId,
376
+ error: extractErrorObject(err)
377
+ }
378
+ });
379
+ }
312
380
  }
313
381
 
314
382
  model.titleFieldId = getContentModelTitleFieldId(fields, titleFieldId);
@@ -1 +1 @@
1
- {"version":3,"names":["defaultTitleFieldId","allowedTitleFieldTypes","getContentModelTitleFieldId","fields","titleFieldId","length","titleField","find","field","getBaseFieldType","multipleValues","fieldId","target","f","WebinyError","includes","type","join","storageId","extractInvalidField","model","err","sdl","source","body","line","lineNumber","locations","sdlLines","split","sdlLine","gqlType","i","match","invalidField","undefined","Array","isArray","fieldRegex","RegExp","matched","message","data","modelId","code","createValidateChildFields","plugins","originalFields","validateFields","lockedFields","params","fieldIdList","storageIdList","validateChildFields","baseType","plugin","fieldType","Error","originalField","id","isLocked","some","lockedField","createFieldStorageId","push","label","validate","validateModelFields","original","fieldTypePlugins","byType","sorterPlugins","CmsGraphQLSchemaSorterPlugin","schema","createManageSDL","reduce","acc","pl","gql","cmsLockedFieldPlugins","existingField","item","reason","lockedFieldType","existingFieldType","lockedFieldsByType","filter","checkLockedField"],"sources":["validateModelFields.ts"],"sourcesContent":["import {\n CmsModel,\n CmsModelField,\n CmsModelFieldToGraphQLPlugin,\n CmsModelFieldToGraphQLPluginValidateChildFieldsValidate,\n CmsModelLockedFieldPlugin,\n LockedField\n} from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { createManageSDL } from \"~/graphql/schema/createManageSDL\";\nimport gql from \"graphql-tag\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createFieldStorageId } from \"./createFieldStorageId\";\nimport { GraphQLError } from \"graphql\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\nimport { CmsGraphQLSchemaSorterPlugin } from \"~/plugins\";\n\nconst defaultTitleFieldId = \"id\";\n\nconst allowedTitleFieldTypes = [\"text\", \"number\"];\n\nconst getContentModelTitleFieldId = (fields: CmsModelField[], titleFieldId?: string): string => {\n /**\n * If there are no fields defined, we will return the default field\n */\n if (fields.length === 0) {\n return defaultTitleFieldId;\n }\n /**\n * if there is no title field defined either in input data or existing content model data\n * we will take first text field that has no multiple values enabled\n * or if initial titleFieldId is the default one also try to find first available text field\n */\n if (!titleFieldId || titleFieldId === defaultTitleFieldId) {\n const titleField = fields.find(field => {\n return 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\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) {\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}\nconst validateFields = (params: ValidateFieldsParams) => {\n const { plugins, fields, originalFields, lockedFields } = params;\n\n const fieldIdList: string[] = [];\n\n const storageIdList: string[] = [];\n\n const validateChildFields = createValidateChildFields(plugins);\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 const originalField = originalFields.find(f => f.id === field.id);\n /**\n * Field MUST have an fieldId defined.\n */\n if (!field.fieldId) {\n throw new WebinyError(`Field does not have an \"fieldId\" defined.`, \"MISSING_FIELD_ID\", {\n field\n });\n }\n /**\n * If storageId does not match a certain pattern, add that pattern, but only if field is not locked (used) already.\n * This is to avoid errors in the already installed systems.\n *\n * Why are we using the @?\n *\n * It is not part of special characters for the query syntax in the Lucene.\n *\n * Relevant links:\n * https://lucene.apache.org/core/3_4_0/queryparsersyntax.html\n * https://discuss.elastic.co/t/special-characters-in-field-names/10658/3\n * https://discuss.elastic.co/t/illegal-characters-in-elasticsearch-field-names/17196/2\n */\n const isLocked = lockedFields.some(lockedField => {\n return lockedField.fieldId === field.storageId;\n });\n if (!field.storageId) {\n /**\n * In case field is locked, we must set the storageId to the fieldId value.\n * This should not happen, because we upgrade all the fields in 5.33.0, but let's have a check just in case of some upgrade miss.\n */\n //\n if (isLocked) {\n field.storageId = field.fieldId;\n }\n /**\n * When having original field, just set the storageId to value from the originalField\n */\n //\n else if (originalField) {\n field.storageId = originalField.storageId;\n }\n /**\n * The last case is when no original field and not locked - so this is a completely new field.\n */\n //\n else {\n field.storageId = createFieldStorageId(field);\n }\n }\n /**\n * Check the field's fieldId against existing ones.\n * There cannot be two fields with the same fieldId - outside world identifier.\n */\n if (fieldIdList.includes(field.fieldId)) {\n throw new WebinyError(\n `Cannot update content model because field \"${field.storageId}\" has fieldId \"${field.fieldId}\", which is already used.`\n );\n }\n fieldIdList.push(field.fieldId);\n /**\n * Check the field's storageId against the existing ones.\n * There cannot be two fields with the same storageId.\n */\n if (storageIdList.includes(field.storageId)) {\n throw new WebinyError(\n `Cannot update content model because field \"${field.label}\" has storageId \"${field.storageId}\", which is already used.`\n );\n }\n storageIdList.push(field.storageId);\n /**\n * 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 plugin.validateChildFields({\n field,\n originalField,\n validate: validateChildFields\n });\n }\n};\n\ninterface ValidateModelFieldsParams {\n model: CmsModel;\n original?: CmsModel;\n plugins: PluginsContainer;\n}\nexport const validateModelFields = (params: ValidateModelFieldsParams) => {\n const { model, original, plugins } = params;\n const { titleFieldId } = model;\n\n /**\n * There should be fields/locked fields in either model or data to be updated.\n */\n const { fields = [], lockedFields = [] } = model;\n\n /**\n * Let's inspect the fields of the received content model. We prevent saving of a content model if it\n * contains a field for which a \"cms-model-field-to-graphql\" plugin does not exist on the backend.\n */\n const fieldTypePlugins = plugins.byType<CmsModelFieldToGraphQLPlugin>(\n \"cms-model-field-to-graphql\"\n );\n const sorterPlugins = plugins.byType<CmsGraphQLSchemaSorterPlugin>(\n CmsGraphQLSchemaSorterPlugin.type\n );\n\n validateFields({\n fields,\n originalFields: original?.fields || [],\n lockedFields,\n plugins: fieldTypePlugins\n });\n\n if (fields.length) {\n /**\n * Make sure that this model can be safely converted to a GraphQL SDL\n */\n const schema = createManageSDL({\n model,\n fieldTypePlugins: fieldTypePlugins.reduce(\n (acc, pl) => ({ ...acc, [pl.fieldType]: pl }),\n {}\n ),\n sorterPlugins\n });\n\n try {\n gql(schema);\n } catch (err) {\n throw new WebinyError(extractInvalidField(model, err));\n }\n }\n\n model.titleFieldId = getContentModelTitleFieldId(fields, titleFieldId);\n\n const cmsLockedFieldPlugins =\n plugins.byType<CmsModelLockedFieldPlugin>(\"cms-model-locked-field\");\n\n /**\n * We must not allow removal or changes in fields that are already in use in content entries.\n * Locked fields still have fieldId (should be storageId) because of the old existing locked fields in the models.\n */\n for (const lockedField of lockedFields) {\n const existingField = fields.find(item => item.storageId === lockedField.fieldId);\n\n /**\n * Starting with 5.33.0 fields can be deleted.\n * Our UI gives a warning upon locked field deletion, but if user is managing fields through API directly - we cannot do anything.\n */\n if (!existingField) {\n continue;\n // throw new WebinyError(\n // `Cannot remove the field \"${lockedField.fieldId}\" because it's already in use in created content.`,\n // \"ENTRY_FIELD_USED\",\n // {\n // lockedField,\n // fields\n // }\n // );\n }\n\n if (lockedField.multipleValues !== existingField.multipleValues) {\n throw new WebinyError(\n `Cannot change \"multipleValues\" for the \"${lockedField.fieldId}\" field because it's already in use in created content.`,\n \"ENTRY_FIELD_USED\",\n {\n 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"],"mapp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oCgD,WAAW,CAACnD,OAAQ,yDADvD,EAEF,kBAFE,EAGF;QACIuE,MAAM,EAAG,gBADb;QAEIC,eAAe,EAAErB,WAAW,CAAC9C,IAFjC;QAGIoE,iBAAiB,EAAE5B;MAHvB,CAHE,CAAN;IASH;IAED;AACR;AACA;;;IACQ,MAAM6B,kBAAkB,GAAGN,qBAAqB,CAACO,MAAtB,CACvBT,EAAE,IAAIA,EAAE,CAACrB,SAAH,KAAiB,IAAA/C,kCAAA,EAAiBqD,WAAjB,CADA,CAA3B;;IAGA,KAAK,MAAMP,MAAX,IAAqB8B,kBAArB,EAAyC;MACrC,IAAI,OAAO9B,MAAM,CAACgC,gBAAd,KAAmC,UAAvC,EAAmD;QAC/C;MACH;;MACDhC,MAAM,CAACgC,gBAAP,CAAwB;QACpBzB,WADoB;QAEpBtD,KAAK,EAAEwE;MAFa,CAAxB;IAIH;EACJ;AACJ,CAnHM"}
1
+ {"version":3,"names":["defaultTitleFieldId","allowedTitleFieldTypes","getContentModelTitleFieldId","fields","titleFieldId","length","titleField","find","field","getBaseFieldType","multipleValues","fieldId","target","f","WebinyError","includes","type","join","storageId","extractInvalidField","model","err","sdl","source","body","line","lineNumber","locations","sdlLines","split","sdlLine","gqlType","i","match","invalidField","undefined","Array","isArray","fieldRegex","RegExp","matched","message","data","modelId","code","createValidateChildFields","plugins","originalFields","validateFields","lockedFields","params","idList","fieldIdList","storageIdList","baseType","plugin","fieldType","Error","id","push","originalField","isLocked","some","lockedField","createFieldStorageId","label","validateChildFields","validate","createGraphQLSchema","context","modelPlugins","buildSchemaPlugins","models","byType","GraphQLSchemaPlugin","createExecutableSchema","extractErrorObject","error","reduce","output","key","validateModelFields","original","fieldTypePlugins","sorterPlugins","CmsGraphQLSchemaSorterPlugin","schema","createManageSDL","acc","pl","gql","cmsLockedFieldPlugins","existingField","item","reason","lockedFieldType","existingFieldType","lockedFieldsByType","filter","checkLockedField"],"sources":["validateModelFields.ts"],"sourcesContent":["import {\n CmsContext,\n CmsModel,\n CmsModelField,\n CmsModelFieldToGraphQLPlugin,\n CmsModelFieldToGraphQLPluginValidateChildFieldsValidate,\n CmsModelLockedFieldPlugin,\n LockedField\n} from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { createManageSDL } from \"~/graphql/schema/createManageSDL\";\nimport gql from \"graphql-tag\";\nimport { createFieldStorageId } from \"./createFieldStorageId\";\nimport { GraphQLError } from \"graphql\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\nimport { CmsGraphQLSchemaSorterPlugin } from \"~/plugins\";\nimport { buildSchemaPlugins } from \"~/graphql/buildSchemaPlugins\";\nimport { createExecutableSchema } from \"~/graphql/createExecutableSchema\";\nimport { GraphQLSchemaPlugin } from \"@webiny/handler-graphql\";\n\nconst defaultTitleFieldId = \"id\";\n\nconst allowedTitleFieldTypes = [\"text\", \"number\"];\n\nconst getContentModelTitleFieldId = (fields: CmsModelField[], titleFieldId?: string): string => {\n /**\n * If there are no fields defined, we will return the default field\n */\n if (fields.length === 0) {\n return defaultTitleFieldId;\n }\n /**\n * if there is no title field defined either in input data or existing content model data\n * we will take first text field that has no multiple values enabled\n * or if initial titleFieldId is the default one also try to find first available text field\n */\n if (!titleFieldId || titleFieldId === defaultTitleFieldId) {\n const titleField = fields.find(field => {\n return 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\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}\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};\ninterface CreateGraphQLSchemaParams {\n context: CmsContext;\n model: CmsModel;\n}\nconst createGraphQLSchema = async (params: CreateGraphQLSchemaParams): Promise<any> => {\n const { context, model } = params;\n\n const modelPlugins = await buildSchemaPlugins({\n context,\n models: [model]\n });\n\n const plugins = context.plugins.byType<GraphQLSchemaPlugin<CmsContext>>(\n GraphQLSchemaPlugin.type\n );\n plugins.push(...modelPlugins);\n\n return createExecutableSchema({\n 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 model: CmsModel;\n original?: CmsModel;\n context: CmsContext;\n}\nexport const validateModelFields = async (params: ValidateModelFieldsParams): Promise<void> => {\n const { model, original, context } = params;\n const { titleFieldId } = 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 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\n const cmsLockedFieldPlugins =\n plugins.byType<CmsModelLockedFieldPlugin>(\"cms-model-locked-field\");\n\n /**\n * We must not allow removal or changes in fields that are already in use in content entries.\n * Locked fields still have fieldId (should be storageId) because of the old existing locked fields in the models.\n */\n for (const lockedField of lockedFields) {\n const existingField = fields.find(item => item.storageId === lockedField.fieldId);\n\n /**\n * Starting with 5.33.0 fields can be deleted.\n * Our UI gives a warning upon locked field deletion, but if user is managing fields through API directly - we cannot do anything.\n */\n if (!existingField) {\n continue;\n // throw new WebinyError(\n // `Cannot remove the field \"${lockedField.fieldId}\" because it's already in use in created content.`,\n // \"ENTRY_FIELD_USED\",\n // {\n // lockedField,\n // fields\n // }\n // );\n }\n\n if (lockedField.multipleValues !== existingField.multipleValues) {\n throw new WebinyError(\n `Cannot change \"multipleValues\" for the \"${lockedField.fieldId}\" field because it's already in use in created content.`,\n \"ENTRY_FIELD_USED\",\n {\n 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":";;;;;;;;;;;AASA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAEA,MAAMA,mBAAmB,GAAG,IAA5B;AAEA,MAAMC,sBAAsB,GAAG,CAAC,MAAD,EAAS,QAAT,CAA/B;;AAEA,MAAMC,2BAA2B,GAAG,CAACC,MAAD,EAA0BC,YAA1B,KAA4D;EAC5F;AACJ;AACA;EACI,IAAID,MAAM,CAACE,MAAP,KAAkB,CAAtB,EAAyB;IACrB,OAAOL,mBAAP;EACH;EACD;AACJ;AACA;AACA;AACA;;;EACI,IAAI,CAACI,YAAD,IAAiBA,YAAY,KAAKJ,mBAAtC,EAA2D;IACvD,MAAMM,UAAU,GAAGH,MAAM,CAACI,IAAP,CAAYC,KAAK,IAAI;MACpC,OAAO,IAAAC,kCAAA,EAAiBD,KAAjB,MAA4B,MAA5B,IAAsC,CAACA,KAAK,CAACE,cAApD;IACH,CAFkB,CAAnB;IAGA,OAAO,CAAAJ,UAAU,SAAV,IAAAA,UAAU,WAAV,YAAAA,UAAU,CAAEK,OAAZ,KAAuBX,mBAA9B;EACH;EACD;AACJ;AACA;AACA;AACA;;;EACI,MAAMY,MAAM,GAAGT,MAAM,CAACI,IAAP,CAAYM,CAAC,IAAIA,CAAC,CAACF,OAAF,KAAcP,YAA/B,CAAf;;EACA,IAAI,CAACQ,MAAL,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Ad,KAAmC,UAAvC,EAAmD;QAC/C;MACH;;MACD5C,MAAM,CAAC4C,gBAAP,CAAwB;QACpBpC,WADoB;QAEpBvD,KAAK,EAAEoF;MAFa,CAAxB;IAIH;EACJ;AACJ,CAvIM"}
@@ -47,8 +47,6 @@ var _ownership = require("../utils/ownership");
47
47
 
48
48
  var _access = require("../utils/access");
49
49
 
50
- var _validateModelFields = require("./contentModel/validateModelFields");
51
-
52
50
  /**
53
51
  * Given a model, return an array of tags ensuring the `type` tag is set.
54
52
  */
@@ -113,7 +111,7 @@ const createModelsCrud = params => {
113
111
  const getModelsAsPlugins = () => {
114
112
  const tenant = getTenant().id;
115
113
  const locale = getLocale().code;
116
- const models = context.plugins.byType(_CmsModelPlugin.CmsModelPlugin.type)
114
+ return context.plugins.byType(_CmsModelPlugin.CmsModelPlugin.type)
117
115
  /**
118
116
  * We need to filter out models that are not for this tenant or locale.
119
117
  * If it does not have tenant or locale define, it is for every locale and tenant
@@ -139,18 +137,6 @@ const createModelsCrud = params => {
139
137
  webinyVersion: context.WEBINY_VERSION
140
138
  });
141
139
  });
142
- /**
143
- * Only point where we can truly validate the user model is in the runtime.
144
- */
145
-
146
- for (const model of models) {
147
- (0, _validateModelFields.validateModelFields)({
148
- model,
149
- plugins: context.plugins
150
- });
151
- }
152
-
153
- return models;
154
140
  };
155
141
 
156
142
  const modelsGet = async modelId => {
@@ -260,7 +246,7 @@ const createModelsCrud = params => {
260
246
  (0, _beforeCreate.assignModelBeforeCreate)({
261
247
  onModelBeforeCreate,
262
248
  onModelBeforeCreateFrom,
263
- plugins: context.plugins,
249
+ context,
264
250
  storageOperations
265
251
  });
266
252
  (0, _afterCreate.assignModelAfterCreate)({
@@ -269,8 +255,7 @@ const createModelsCrud = params => {
269
255
  });
270
256
  (0, _beforeUpdate.assignModelBeforeUpdate)({
271
257
  onModelBeforeUpdate,
272
- plugins: context.plugins,
273
- storageOperations
258
+ context
274
259
  });
275
260
  (0, _afterUpdate.assignModelAfterUpdate)({
276
261
  context,