@webiny/api-headless-cms 0.0.0-unstable.d65ec29d44 → 0.0.0-unstable.df6d94b531

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 (115) hide show
  1. package/crud/contentEntry/markLockedFields.d.ts +1 -1
  2. package/crud/contentEntry/markLockedFields.js +3 -0
  3. package/crud/contentEntry/markLockedFields.js.map +1 -1
  4. package/crud/contentEntry.crud.d.ts +2 -1
  5. package/crud/contentEntry.crud.js +29 -23
  6. package/crud/contentEntry.crud.js.map +1 -1
  7. package/crud/contentModel/beforeCreate.js +4 -0
  8. package/crud/contentModel/beforeCreate.js.map +1 -1
  9. package/crud/contentModel/beforeUpdate.js +4 -0
  10. package/crud/contentModel/beforeUpdate.js.map +1 -1
  11. package/crud/contentModel/compatibility/modelApiName.d.ts +3 -0
  12. package/crud/contentModel/compatibility/modelApiName.js +24 -0
  13. package/crud/contentModel/compatibility/modelApiName.js.map +1 -0
  14. package/crud/contentModel/defaultFields.d.ts +5 -0
  15. package/crud/contentModel/defaultFields.js +58 -0
  16. package/crud/contentModel/defaultFields.js.map +1 -0
  17. package/crud/contentModel/fields/descriptionField.d.ts +2 -0
  18. package/crud/contentModel/fields/descriptionField.js +42 -0
  19. package/crud/contentModel/fields/descriptionField.js.map +1 -0
  20. package/crud/contentModel/fields/imageField.d.ts +2 -0
  21. package/crud/contentModel/fields/imageField.js +46 -0
  22. package/crud/contentModel/fields/imageField.js.map +1 -0
  23. package/crud/contentModel/fields/titleField.d.ts +2 -0
  24. package/crud/contentModel/fields/titleField.js +58 -0
  25. package/crud/contentModel/fields/titleField.js.map +1 -0
  26. package/crud/contentModel/systemFields.js.map +1 -1
  27. package/crud/contentModel/validateModel.d.ts +1 -0
  28. package/crud/contentModel/validateModel.js.map +1 -1
  29. package/crud/contentModel/validateModelFields.d.ts +2 -1
  30. package/crud/contentModel/validateModelFields.js +17 -55
  31. package/crud/contentModel/validateModelFields.js.map +1 -1
  32. package/crud/contentModel/validation.d.ts +92 -50
  33. package/crud/contentModel/validation.js +59 -11
  34. package/crud/contentModel/validation.js.map +1 -1
  35. package/crud/contentModel.crud.js +40 -18
  36. package/crud/contentModel.crud.js.map +1 -1
  37. package/crud/system.crud.js +0 -60
  38. package/crud/system.crud.js.map +1 -1
  39. package/graphql/createExecutableSchema.d.ts +2 -3
  40. package/graphql/createExecutableSchema.js.map +1 -1
  41. package/graphql/graphQLHandlerFactory.js +13 -8
  42. package/graphql/graphQLHandlerFactory.js.map +1 -1
  43. package/graphql/schema/baseContentSchema.js +1 -7
  44. package/graphql/schema/baseContentSchema.js.map +1 -1
  45. package/graphql/schema/contentEntries.js +90 -53
  46. package/graphql/schema/contentEntries.js.map +1 -1
  47. package/graphql/schema/contentModelGroups.js +1 -1
  48. package/graphql/schema/contentModelGroups.js.map +1 -1
  49. package/graphql/schema/contentModels.js +20 -1
  50. package/graphql/schema/contentModels.js.map +1 -1
  51. package/graphql/schema/createManageResolvers.d.ts +1 -1
  52. package/graphql/schema/createManageResolvers.js +33 -17
  53. package/graphql/schema/createManageResolvers.js.map +1 -1
  54. package/graphql/schema/createManageSDL.d.ts +1 -0
  55. package/graphql/schema/createManageSDL.js +55 -49
  56. package/graphql/schema/createManageSDL.js.map +1 -1
  57. package/graphql/schema/createPreviewResolvers.js +3 -7
  58. package/graphql/schema/createPreviewResolvers.js.map +1 -1
  59. package/graphql/schema/createReadResolvers.js +4 -8
  60. package/graphql/schema/createReadResolvers.js.map +1 -1
  61. package/graphql/schema/createReadSDL.d.ts +1 -0
  62. package/graphql/schema/createReadSDL.js +24 -22
  63. package/graphql/schema/createReadSDL.js.map +1 -1
  64. package/graphql/schema/resolvers/commonFieldResolvers.d.ts +3 -2
  65. package/graphql/schema/resolvers/commonFieldResolvers.js +2 -1
  66. package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -1
  67. package/graphql/schema/schemaPlugins.js +12 -12
  68. package/graphql/schema/schemaPlugins.js.map +1 -1
  69. package/graphql/system.js +0 -16
  70. package/graphql/system.js.map +1 -1
  71. package/graphqlFields/dynamicZone/dynamicZoneField.js +12 -4
  72. package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -1
  73. package/graphqlFields/object.js +21 -2
  74. package/graphqlFields/object.js.map +1 -1
  75. package/graphqlFields/ref.js +42 -14
  76. package/graphqlFields/ref.js.map +1 -1
  77. package/index.d.ts +3 -1
  78. package/index.js +22 -3
  79. package/index.js.map +1 -1
  80. package/package.json +22 -23
  81. package/plugins/CmsModelPlugin.d.ts +11 -1
  82. package/plugins/CmsModelPlugin.js +13 -2
  83. package/plugins/CmsModelPlugin.js.map +1 -1
  84. package/types.d.ts +75 -21
  85. package/types.js +1 -1
  86. package/types.js.map +1 -1
  87. package/upgrades/5.33.0/index.js +26 -3
  88. package/upgrades/5.33.0/index.js.map +1 -1
  89. package/upgrades/index.js +3 -0
  90. package/upgrades/index.js.map +1 -1
  91. package/utils/converters/valueKeyStorageConverter.d.ts +1 -1
  92. package/utils/converters/valueKeyStorageConverter.js +2 -1
  93. package/utils/converters/valueKeyStorageConverter.js.map +1 -1
  94. package/utils/createTypeFromFields.d.ts +1 -0
  95. package/utils/createTypeFromFields.js +7 -4
  96. package/utils/createTypeFromFields.js.map +1 -1
  97. package/utils/getEntryDescription.d.ts +2 -0
  98. package/utils/getEntryDescription.js +17 -0
  99. package/utils/getEntryDescription.js.map +1 -0
  100. package/utils/getEntryImage.d.ts +2 -0
  101. package/utils/getEntryImage.js +17 -0
  102. package/utils/getEntryImage.js.map +1 -0
  103. package/utils/incrementEntryIdVersion.d.ts +5 -0
  104. package/utils/incrementEntryIdVersion.js +29 -0
  105. package/utils/incrementEntryIdVersion.js.map +1 -0
  106. package/utils/ownership.d.ts +3 -3
  107. package/utils/ownership.js.map +1 -1
  108. package/utils/pluralizedTypeName.js +6 -0
  109. package/utils/pluralizedTypeName.js.map +1 -1
  110. package/utils/renderFields.d.ts +2 -1
  111. package/utils/renderFields.js +8 -1
  112. package/utils/renderFields.js.map +1 -1
  113. package/utils/renderInputFields.d.ts +2 -1
  114. package/utils/renderInputFields.js +4 -0
  115. package/utils/renderInputFields.js.map +1 -1
@@ -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","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,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,oBAAoB,CACvB;AACD;AACA;AACA;AACA;AACA,MAAMC,2BAAqC,GAAG,CAC1C,UAAU,EACV,MAAM,EACN,MAAM,EACN,OAAO,EACP,QAAQ,EACR,SAAS,CACZ;;AAED;AACA;AACA;AACA;AACA,MAAMC,sBAAsB,GAAG,CAACC,WAAqB,EAAEC,OAAe,KAAK;EACvE,IAAID,WAAW,CAACE,QAAQ,CAACD,OAAO,CAAC,KAAK,IAAI,EAAE;IACxC,MAAM,IAAIE,cAAW,CAChB,+BAA8BF,OAAQ,mBAAkB,EACzD,iBAAiB,EACjB;MACIA;IACJ,CAAC,CACJ;EACL;EACA;AACJ;AACA;AACA;AACA;EACI,MAAMG,0BAA0B,GAAG,IAAAC,kBAAS,EAACJ,OAAO,CAAC;EACrD,IAAID,WAAW,CAACE,QAAQ,CAACE,0BAA0B,CAAC,KAAK,IAAI,EAAE;IAC3D,MAAM,IAAID,cAAW,CAChB,+BAA8BF,OAAQ,+CAA8CG,0BAA2B,SAAQ,EACxH,uBAAuB,EACvB;MACIH,OAAO;MACPK,MAAM,EAAEF;IACZ,CAAC,CACJ;EACL;;EAEA;AACJ;AACA;EACI,MAAMG,4BAA4B,GAAGF,kBAAS,CAACG,QAAQ,CAACP,OAAO,CAAC;EAChE,IAAID,WAAW,CAACE,QAAQ,CAACK,4BAA4B,CAAC,KAAK,IAAI,EAAE;IAC7D,MAAM,IAAIJ,cAAW,CAChB,+BAA8BF,OAAQ,+CAA8CM,4BAA6B,SAAQ,EAC1H,yBAAyB,EACzB;MACIN,OAAO;MACPO,QAAQ,EAAED;IACd,CAAC,CACJ;EACL;AACJ,CAAC;AAED,MAAME,mBAAmB,GAAIR,OAAe,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,CAAC,CAAC;IACF,MAAM0B,EAAE,CAAC;MACL/B,KAAK;MACL2B;IACJ,CAAC,CAAC;IACF;AACR;AACA;IACQ,MAAM,IAAAK,4BAAa,EAAC;MAChBhC,KAAK;MACLyB;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;EAEFD,uBAAuB,CAACE,SAAS,CAC7BtB,qBAAqB,CAAC;IAClBE,iBAAiB;IACjBD,OAAO,EAAEoB,OAAO,CAACpB;EACrB,CAAC,CAAC,CACL;AACL,CAAC;AAAC"}
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","security","disableAuthorization","cms","listModels","enableAuthorization","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 context.security.disableAuthorization();\n const models = await context.cms.listModels();\n context.security.enableAuthorization();\n /**\n * and then we move onto model and fields...\n */\n await validateModel({\n models,\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,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,oBAAoB,CACvB;AACD;AACA;AACA;AACA;AACA,MAAMC,2BAAqC,GAAG,CAC1C,UAAU,EACV,MAAM,EACN,MAAM,EACN,OAAO,EACP,QAAQ,EACR,SAAS,CACZ;;AAED;AACA;AACA;AACA;AACA,MAAMC,sBAAsB,GAAG,CAACC,WAAqB,EAAEC,OAAe,KAAK;EACvE,IAAID,WAAW,CAACE,QAAQ,CAACD,OAAO,CAAC,KAAK,IAAI,EAAE;IACxC,MAAM,IAAIE,cAAW,CAChB,+BAA8BF,OAAQ,mBAAkB,EACzD,iBAAiB,EACjB;MACIA;IACJ,CAAC,CACJ;EACL;EACA;AACJ;AACA;AACA;AACA;EACI,MAAMG,0BAA0B,GAAG,IAAAC,kBAAS,EAACJ,OAAO,CAAC;EACrD,IAAID,WAAW,CAACE,QAAQ,CAACE,0BAA0B,CAAC,KAAK,IAAI,EAAE;IAC3D,MAAM,IAAID,cAAW,CAChB,+BAA8BF,OAAQ,+CAA8CG,0BAA2B,SAAQ,EACxH,uBAAuB,EACvB;MACIH,OAAO;MACPK,MAAM,EAAEF;IACZ,CAAC,CACJ;EACL;;EAEA;AACJ;AACA;EACI,MAAMG,4BAA4B,GAAGF,kBAAS,CAACG,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,mBAAmB,CAACG,SAAS,CAAC,OAAO;IAAE1B,KAAK;IAAE2B;EAAM,CAAC,KAAK;IACtD;AACR;AACA;IACQ,IAAAC,8BAAc,EAAC5B,KAAK,CAAC6B,MAAM,EAAE7B,KAAK,CAAC8B,MAAM,CAAC;IAC1C;AACR;AACA;IACQ,MAAMC,EAAE,GAAG3B,qBAAqB,CAAC;MAC7BE,iBAAiB;MACjBD,OAAO,EAAEoB,OAAO,CAACpB;IACrB,CAAC,CAAC;IACF,MAAM0B,EAAE,CAAC;MACL/B,KAAK;MACL2B;IACJ,CAAC,CAAC;IACFF,OAAO,CAACO,QAAQ,CAACC,oBAAoB,EAAE;IACvC,MAAMlB,MAAM,GAAG,MAAMU,OAAO,CAACS,GAAG,CAACC,UAAU,EAAE;IAC7CV,OAAO,CAACO,QAAQ,CAACI,mBAAmB,EAAE;IACtC;AACR;AACA;IACQ,MAAM,IAAAC,4BAAa,EAAC;MAChBtB,MAAM;MACNf,KAAK;MACLyB;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;EAEFD,uBAAuB,CAACE,SAAS,CAC7BtB,qBAAqB,CAAC;IAClBE,iBAAiB;IACjBD,OAAO,EAAEoB,OAAO,CAACpB;EACrB,CAAC,CAAC,CACL;AACL,CAAC;AAAC"}
@@ -19,10 +19,14 @@ const assignModelBeforeUpdate = params => {
19
19
  * First we go through the layout...
20
20
  */
21
21
  (0, _validateLayout.validateLayout)(model.layout, model.fields);
22
+ context.security.disableAuthorization();
23
+ const models = await context.cms.listModels();
24
+ context.security.enableAuthorization();
22
25
  /**
23
26
  * then the model and fields...
24
27
  */
25
28
  await (0, _validateModel.validateModel)({
29
+ models,
26
30
  model,
27
31
  original,
28
32
  context
@@ -1 +1 @@
1
- {"version":3,"names":["assignModelBeforeUpdate","params","onModelBeforeUpdate","context","subscribe","model","original","validateLayout","layout","fields","validateModel"],"sources":["beforeUpdate.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { OnModelBeforeUpdateTopicParams, CmsContext } from \"~/types\";\nimport { validateModel } from \"./validateModel\";\nimport { validateLayout } from \"./validateLayout\";\n\ninterface AssignBeforeModelUpdateParams {\n onModelBeforeUpdate: Topic<OnModelBeforeUpdateTopicParams>;\n context: CmsContext;\n}\n\nexport const assignModelBeforeUpdate = (params: AssignBeforeModelUpdateParams) => {\n const { onModelBeforeUpdate, context } = params;\n\n onModelBeforeUpdate.subscribe(async ({ model, original }) => {\n /**\n * First we go through the layout...\n */\n validateLayout(model.layout, model.fields);\n /**\n * then the model and fields...\n */\n await validateModel({\n model,\n original,\n context\n });\n });\n};\n"],"mappings":";;;;;;AAEA;AACA;AAOO,MAAMA,uBAAuB,GAAIC,MAAqC,IAAK;EAC9E,MAAM;IAAEC,mBAAmB;IAAEC;EAAQ,CAAC,GAAGF,MAAM;EAE/CC,mBAAmB,CAACE,SAAS,CAAC,OAAO;IAAEC,KAAK;IAAEC;EAAS,CAAC,KAAK;IACzD;AACR;AACA;IACQ,IAAAC,8BAAc,EAACF,KAAK,CAACG,MAAM,EAAEH,KAAK,CAACI,MAAM,CAAC;IAC1C;AACR;AACA;IACQ,MAAM,IAAAC,4BAAa,EAAC;MAChBL,KAAK;MACLC,QAAQ;MACRH;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AAAC"}
1
+ {"version":3,"names":["assignModelBeforeUpdate","params","onModelBeforeUpdate","context","subscribe","model","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"}
@@ -0,0 +1,3 @@
1
+ import { CmsModel } from "../../../types";
2
+ export declare const ensureSingularApiName: (model: CmsModel) => string;
3
+ export declare const ensurePluralApiName: (model: CmsModel) => string;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.ensureSingularApiName = exports.ensurePluralApiName = void 0;
8
+ var _camelCase = _interopRequireDefault(require("lodash/camelCase"));
9
+ var _upperFirst = _interopRequireDefault(require("lodash/upperFirst"));
10
+ var _pluralize = _interopRequireDefault(require("pluralize"));
11
+ const ensureSingularApiName = model => {
12
+ if (!model.singularApiName) {
13
+ return (0, _upperFirst.default)((0, _camelCase.default)(model.modelId));
14
+ }
15
+ return model.singularApiName;
16
+ };
17
+ exports.ensureSingularApiName = ensureSingularApiName;
18
+ const ensurePluralApiName = model => {
19
+ if (!model.pluralApiName) {
20
+ return (0, _pluralize.default)(ensureSingularApiName(model));
21
+ }
22
+ return model.pluralApiName;
23
+ };
24
+ exports.ensurePluralApiName = ensurePluralApiName;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ensureSingularApiName","model","singularApiName","upperFirst","camelCase","modelId","ensurePluralApiName","pluralApiName","pluralize"],"sources":["modelApiName.ts"],"sourcesContent":["import camelCase from \"lodash/camelCase\";\nimport upperFirst from \"lodash/upperFirst\";\nimport pluralize from \"pluralize\";\nimport { CmsModel } from \"~/types\";\n\nexport const ensureSingularApiName = (model: CmsModel): string => {\n if (!model.singularApiName) {\n return upperFirst(camelCase(model.modelId));\n }\n return model.singularApiName;\n};\n\nexport const ensurePluralApiName = (model: CmsModel): string => {\n if (!model.pluralApiName) {\n return pluralize(ensureSingularApiName(model));\n }\n return model.pluralApiName;\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAGO,MAAMA,qBAAqB,GAAIC,KAAe,IAAa;EAC9D,IAAI,CAACA,KAAK,CAACC,eAAe,EAAE;IACxB,OAAO,IAAAC,mBAAU,EAAC,IAAAC,kBAAS,EAACH,KAAK,CAACI,OAAO,CAAC,CAAC;EAC/C;EACA,OAAOJ,KAAK,CAACC,eAAe;AAChC,CAAC;AAAC;AAEK,MAAMI,mBAAmB,GAAIL,KAAe,IAAa;EAC5D,IAAI,CAACA,KAAK,CAACM,aAAa,EAAE;IACtB,OAAO,IAAAC,kBAAS,EAACR,qBAAqB,CAACC,KAAK,CAAC,CAAC;EAClD;EACA,OAAOA,KAAK,CAACM,aAAa;AAC9B,CAAC;AAAC"}
@@ -0,0 +1,5 @@
1
+ import { CmsModelCreateInput } from "../../types";
2
+ /**
3
+ * We only assign default fields if there are no fields in the model already.
4
+ */
5
+ export declare const assignModelDefaultFields: (model: CmsModelCreateInput) => void;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.assignModelDefaultFields = void 0;
7
+ var _utils = require("@webiny/utils");
8
+ const createDefaultFields = () => {
9
+ return [{
10
+ id: (0, _utils.generateAlphaNumericLowerCaseId)(8),
11
+ fieldId: "title",
12
+ type: "text",
13
+ label: "Title",
14
+ validation: [{
15
+ name: "required",
16
+ message: "Title is a required field."
17
+ }],
18
+ listValidation: [],
19
+ renderer: {
20
+ name: "text-input"
21
+ }
22
+ }, {
23
+ id: (0, _utils.generateAlphaNumericLowerCaseId)(8),
24
+ fieldId: "description",
25
+ type: "long-text",
26
+ label: "Description",
27
+ validation: [],
28
+ listValidation: [],
29
+ renderer: {
30
+ name: "long-text-text-area"
31
+ }
32
+ }, {
33
+ id: (0, _utils.generateAlphaNumericLowerCaseId)(8),
34
+ fieldId: "image",
35
+ type: "file",
36
+ label: "Image",
37
+ validation: [],
38
+ listValidation: [],
39
+ renderer: {
40
+ name: "file-input"
41
+ },
42
+ settings: {
43
+ imagesOnly: true
44
+ }
45
+ }];
46
+ };
47
+
48
+ /**
49
+ * We only assign default fields if there are no fields in the model already.
50
+ */
51
+ const assignModelDefaultFields = model => {
52
+ if (model.fields && model.fields.length !== 0) {
53
+ return;
54
+ }
55
+ model.fields = createDefaultFields();
56
+ model.layout = [[model.fields[0].id], [model.fields[1].id, model.fields[2].id]];
57
+ };
58
+ exports.assignModelDefaultFields = assignModelDefaultFields;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createDefaultFields","id","generateAlphaNumericLowerCaseId","fieldId","type","label","validation","name","message","listValidation","renderer","settings","imagesOnly","assignModelDefaultFields","model","fields","length","layout"],"sources":["defaultFields.ts"],"sourcesContent":["import { CmsModelCreateInput, CmsModelFieldInput } from \"~/types\";\nimport { generateAlphaNumericLowerCaseId } from \"@webiny/utils\";\n\nconst createDefaultFields = (): CmsModelFieldInput[] => {\n return [\n {\n id: generateAlphaNumericLowerCaseId(8),\n fieldId: \"title\",\n type: \"text\",\n label: \"Title\",\n validation: [\n {\n name: \"required\",\n message: \"Title is a required field.\"\n }\n ],\n listValidation: [],\n renderer: {\n name: \"text-input\"\n }\n },\n {\n id: generateAlphaNumericLowerCaseId(8),\n fieldId: \"description\",\n type: \"long-text\",\n label: \"Description\",\n validation: [],\n listValidation: [],\n renderer: {\n name: \"long-text-text-area\"\n }\n },\n {\n id: generateAlphaNumericLowerCaseId(8),\n fieldId: \"image\",\n type: \"file\",\n label: \"Image\",\n validation: [],\n listValidation: [],\n renderer: {\n name: \"file-input\"\n },\n settings: {\n imagesOnly: true\n }\n }\n ];\n};\n\n/**\n * We only assign default fields if there are no fields in the model already.\n */\nexport const assignModelDefaultFields = (model: CmsModelCreateInput): void => {\n if (model.fields && model.fields.length !== 0) {\n return;\n }\n\n model.fields = createDefaultFields();\n model.layout = [[model.fields[0].id], [model.fields[1].id, model.fields[2].id]];\n};\n"],"mappings":";;;;;;AACA;AAEA,MAAMA,mBAAmB,GAAG,MAA4B;EACpD,OAAO,CACH;IACIC,EAAE,EAAE,IAAAC,sCAA+B,EAAC,CAAC,CAAC;IACtCC,OAAO,EAAE,OAAO;IAChBC,IAAI,EAAE,MAAM;IACZC,KAAK,EAAE,OAAO;IACdC,UAAU,EAAE,CACR;MACIC,IAAI,EAAE,UAAU;MAChBC,OAAO,EAAE;IACb,CAAC,CACJ;IACDC,cAAc,EAAE,EAAE;IAClBC,QAAQ,EAAE;MACNH,IAAI,EAAE;IACV;EACJ,CAAC,EACD;IACIN,EAAE,EAAE,IAAAC,sCAA+B,EAAC,CAAC,CAAC;IACtCC,OAAO,EAAE,aAAa;IACtBC,IAAI,EAAE,WAAW;IACjBC,KAAK,EAAE,aAAa;IACpBC,UAAU,EAAE,EAAE;IACdG,cAAc,EAAE,EAAE;IAClBC,QAAQ,EAAE;MACNH,IAAI,EAAE;IACV;EACJ,CAAC,EACD;IACIN,EAAE,EAAE,IAAAC,sCAA+B,EAAC,CAAC,CAAC;IACtCC,OAAO,EAAE,OAAO;IAChBC,IAAI,EAAE,MAAM;IACZC,KAAK,EAAE,OAAO;IACdC,UAAU,EAAE,EAAE;IACdG,cAAc,EAAE,EAAE;IAClBC,QAAQ,EAAE;MACNH,IAAI,EAAE;IACV,CAAC;IACDI,QAAQ,EAAE;MACNC,UAAU,EAAE;IAChB;EACJ,CAAC,CACJ;AACL,CAAC;;AAED;AACA;AACA;AACO,MAAMC,wBAAwB,GAAIC,KAA0B,IAAW;EAC1E,IAAIA,KAAK,CAACC,MAAM,IAAID,KAAK,CAACC,MAAM,CAACC,MAAM,KAAK,CAAC,EAAE;IAC3C;EACJ;EAEAF,KAAK,CAACC,MAAM,GAAGf,mBAAmB,EAAE;EACpCc,KAAK,CAACG,MAAM,GAAG,CAAC,CAACH,KAAK,CAACC,MAAM,CAAC,CAAC,CAAC,CAACd,EAAE,CAAC,EAAE,CAACa,KAAK,CAACC,MAAM,CAAC,CAAC,CAAC,CAACd,EAAE,EAAEa,KAAK,CAACC,MAAM,CAAC,CAAC,CAAC,CAACd,EAAE,CAAC,CAAC;AACnF,CAAC;AAAC"}
@@ -0,0 +1,2 @@
1
+ import { CmsModelField } from "../../../types";
2
+ export declare const getContentModelDescriptionFieldId: (fields: CmsModelField[], descriptionFieldId?: string | null) => string | null | undefined;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getContentModelDescriptionFieldId = void 0;
8
+ var _getBaseFieldType = require("../../../utils/getBaseFieldType");
9
+ var _error = _interopRequireDefault(require("@webiny/error"));
10
+ const getContentModelDescriptionFieldId = (fields, descriptionFieldId) => {
11
+ /**
12
+ * If there are no fields defined, we will just set as null.
13
+ */
14
+ if (fields.length === 0) {
15
+ return null;
16
+ }
17
+ /**
18
+ * If description field is not defined, let us find possible one.
19
+ */
20
+ if (!descriptionFieldId) {
21
+ const descriptionField = fields.find(field => {
22
+ return (0, _getBaseFieldType.getBaseFieldType)(field) === "long-text" && !field.multipleValues;
23
+ });
24
+ return (descriptionField === null || descriptionField === void 0 ? void 0 : descriptionField.fieldId) || null;
25
+ }
26
+ const target = fields.find(field => field.fieldId === descriptionFieldId && (0, _getBaseFieldType.getBaseFieldType)(field) === "long-text");
27
+ if (!target) {
28
+ throw new _error.default(`Field selected for the description field does not exist in the model.`, "VALIDATION_ERROR", {
29
+ fieldId: descriptionFieldId,
30
+ fields
31
+ });
32
+ }
33
+ if (target.multipleValues) {
34
+ throw new _error.default(`Fields that accept multiple values cannot be used as the entry description.`, "ENTRY_TITLE_FIELD_TYPE", {
35
+ storageId: target.storageId,
36
+ fieldId: target.fieldId,
37
+ type: target.type
38
+ });
39
+ }
40
+ return target.fieldId;
41
+ };
42
+ exports.getContentModelDescriptionFieldId = getContentModelDescriptionFieldId;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getContentModelDescriptionFieldId","fields","descriptionFieldId","length","descriptionField","find","field","getBaseFieldType","multipleValues","fieldId","target","WebinyError","storageId","type"],"sources":["descriptionField.ts"],"sourcesContent":["import { CmsModelField } from \"~/types\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\nimport WebinyError from \"@webiny/error\";\n\nexport const getContentModelDescriptionFieldId = (\n fields: CmsModelField[],\n descriptionFieldId?: string | null\n): string | null | undefined => {\n /**\n * If there are no fields defined, we will just set as null.\n */\n if (fields.length === 0) {\n return null;\n }\n /**\n * If description field is not defined, let us find possible one.\n */\n if (!descriptionFieldId) {\n const descriptionField = fields.find(field => {\n return getBaseFieldType(field) === \"long-text\" && !field.multipleValues;\n });\n return descriptionField?.fieldId || null;\n }\n const target = fields.find(\n field => field.fieldId === descriptionFieldId && getBaseFieldType(field) === \"long-text\"\n );\n if (!target) {\n throw new WebinyError(\n `Field selected for the description field does not exist in the model.`,\n \"VALIDATION_ERROR\",\n {\n fieldId: descriptionFieldId,\n fields\n }\n );\n }\n if (target.multipleValues) {\n throw new WebinyError(\n `Fields that accept multiple values cannot be used as the entry description.`,\n \"ENTRY_TITLE_FIELD_TYPE\",\n {\n storageId: target.storageId,\n fieldId: target.fieldId,\n type: target.type\n }\n );\n }\n\n return target.fieldId;\n};\n"],"mappings":";;;;;;;AACA;AACA;AAEO,MAAMA,iCAAiC,GAAG,CAC7CC,MAAuB,EACvBC,kBAAkC,KACN;EAC5B;AACJ;AACA;EACI,IAAID,MAAM,CAACE,MAAM,KAAK,CAAC,EAAE;IACrB,OAAO,IAAI;EACf;EACA;AACJ;AACA;EACI,IAAI,CAACD,kBAAkB,EAAE;IACrB,MAAME,gBAAgB,GAAGH,MAAM,CAACI,IAAI,CAACC,KAAK,IAAI;MAC1C,OAAO,IAAAC,kCAAgB,EAACD,KAAK,CAAC,KAAK,WAAW,IAAI,CAACA,KAAK,CAACE,cAAc;IAC3E,CAAC,CAAC;IACF,OAAO,CAAAJ,gBAAgB,aAAhBA,gBAAgB,uBAAhBA,gBAAgB,CAAEK,OAAO,KAAI,IAAI;EAC5C;EACA,MAAMC,MAAM,GAAGT,MAAM,CAACI,IAAI,CACtBC,KAAK,IAAIA,KAAK,CAACG,OAAO,KAAKP,kBAAkB,IAAI,IAAAK,kCAAgB,EAACD,KAAK,CAAC,KAAK,WAAW,CAC3F;EACD,IAAI,CAACI,MAAM,EAAE;IACT,MAAM,IAAIC,cAAW,CAChB,uEAAsE,EACvE,kBAAkB,EAClB;MACIF,OAAO,EAAEP,kBAAkB;MAC3BD;IACJ,CAAC,CACJ;EACL;EACA,IAAIS,MAAM,CAACF,cAAc,EAAE;IACvB,MAAM,IAAIG,cAAW,CAChB,6EAA4E,EAC7E,wBAAwB,EACxB;MACIC,SAAS,EAAEF,MAAM,CAACE,SAAS;MAC3BH,OAAO,EAAEC,MAAM,CAACD,OAAO;MACvBI,IAAI,EAAEH,MAAM,CAACG;IACjB,CAAC,CACJ;EACL;EAEA,OAAOH,MAAM,CAACD,OAAO;AACzB,CAAC;AAAC"}
@@ -0,0 +1,2 @@
1
+ import { CmsModelField } from "../../../types";
2
+ export declare const getContentModelImageFieldId: (fields: CmsModelField[], imageFieldId?: string | null) => string | null | undefined;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getContentModelImageFieldId = void 0;
8
+ var _getBaseFieldType = require("../../../utils/getBaseFieldType");
9
+ var _error = _interopRequireDefault(require("@webiny/error"));
10
+ const getContentModelImageFieldId = (fields, imageFieldId) => {
11
+ /**
12
+ * If there are no fields defined, we will just set as null.
13
+ */
14
+ if (fields.length === 0) {
15
+ return null;
16
+ }
17
+ /**
18
+ * If image field is not defined, let us find possible one.
19
+ */
20
+ if (!imageFieldId) {
21
+ const imageField = fields.find(field => {
22
+ var _field$settings;
23
+ return (0, _getBaseFieldType.getBaseFieldType)(field) === "file" && !field.multipleValues && ((_field$settings = field.settings) === null || _field$settings === void 0 ? void 0 : _field$settings.imagesOnly);
24
+ });
25
+ return (imageField === null || imageField === void 0 ? void 0 : imageField.fieldId) || null;
26
+ }
27
+ const target = fields.find(field => {
28
+ var _field$settings2;
29
+ return field.fieldId === imageFieldId && (0, _getBaseFieldType.getBaseFieldType)(field) === "file" && ((_field$settings2 = field.settings) === null || _field$settings2 === void 0 ? void 0 : _field$settings2.imagesOnly);
30
+ });
31
+ if (!target) {
32
+ throw new _error.default(`Field selected for the image field does not exist in the model.`, "VALIDATION_ERROR", {
33
+ fieldId: imageFieldId,
34
+ fields
35
+ });
36
+ }
37
+ if (target.multipleValues) {
38
+ throw new _error.default(`Fields that accept multiple values cannot be used as the entry image.`, "ENTRY_TITLE_FIELD_TYPE", {
39
+ storageId: target.storageId,
40
+ fieldId: target.fieldId,
41
+ type: target.type
42
+ });
43
+ }
44
+ return target.fieldId;
45
+ };
46
+ exports.getContentModelImageFieldId = getContentModelImageFieldId;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getContentModelImageFieldId","fields","imageFieldId","length","imageField","find","field","getBaseFieldType","multipleValues","settings","imagesOnly","fieldId","target","WebinyError","storageId","type"],"sources":["imageField.ts"],"sourcesContent":["import { CmsModelField } from \"~/types\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\nimport WebinyError from \"@webiny/error\";\n\nexport const getContentModelImageFieldId = (\n fields: CmsModelField[],\n imageFieldId?: string | null\n): string | null | undefined => {\n /**\n * If there are no fields defined, we will just set as null.\n */\n if (fields.length === 0) {\n return null;\n }\n /**\n * If image field is not defined, let us find possible one.\n */\n if (!imageFieldId) {\n const imageField = fields.find(field => {\n return (\n getBaseFieldType(field) === \"file\" &&\n !field.multipleValues &&\n field.settings?.imagesOnly\n );\n });\n return imageField?.fieldId || null;\n }\n const target = fields.find(\n field =>\n field.fieldId === imageFieldId &&\n getBaseFieldType(field) === \"file\" &&\n field.settings?.imagesOnly\n );\n if (!target) {\n throw new WebinyError(\n `Field selected for the image field does not exist in the model.`,\n \"VALIDATION_ERROR\",\n {\n fieldId: imageFieldId,\n fields\n }\n );\n }\n if (target.multipleValues) {\n throw new WebinyError(\n `Fields that accept multiple values cannot be used as the entry image.`,\n \"ENTRY_TITLE_FIELD_TYPE\",\n {\n storageId: target.storageId,\n fieldId: target.fieldId,\n type: target.type\n }\n );\n }\n\n return target.fieldId;\n};\n"],"mappings":";;;;;;;AACA;AACA;AAEO,MAAMA,2BAA2B,GAAG,CACvCC,MAAuB,EACvBC,YAA4B,KACA;EAC5B;AACJ;AACA;EACI,IAAID,MAAM,CAACE,MAAM,KAAK,CAAC,EAAE;IACrB,OAAO,IAAI;EACf;EACA;AACJ;AACA;EACI,IAAI,CAACD,YAAY,EAAE;IACf,MAAME,UAAU,GAAGH,MAAM,CAACI,IAAI,CAACC,KAAK,IAAI;MAAA;MACpC,OACI,IAAAC,kCAAgB,EAACD,KAAK,CAAC,KAAK,MAAM,IAClC,CAACA,KAAK,CAACE,cAAc,wBACrBF,KAAK,CAACG,QAAQ,oDAAd,gBAAgBC,UAAU;IAElC,CAAC,CAAC;IACF,OAAO,CAAAN,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEO,OAAO,KAAI,IAAI;EACtC;EACA,MAAMC,MAAM,GAAGX,MAAM,CAACI,IAAI,CACtBC,KAAK;IAAA;IAAA,OACDA,KAAK,CAACK,OAAO,KAAKT,YAAY,IAC9B,IAAAK,kCAAgB,EAACD,KAAK,CAAC,KAAK,MAAM,yBAClCA,KAAK,CAACG,QAAQ,qDAAd,iBAAgBC,UAAU;EAAA,EACjC;EACD,IAAI,CAACE,MAAM,EAAE;IACT,MAAM,IAAIC,cAAW,CAChB,iEAAgE,EACjE,kBAAkB,EAClB;MACIF,OAAO,EAAET,YAAY;MACrBD;IACJ,CAAC,CACJ;EACL;EACA,IAAIW,MAAM,CAACJ,cAAc,EAAE;IACvB,MAAM,IAAIK,cAAW,CAChB,uEAAsE,EACvE,wBAAwB,EACxB;MACIC,SAAS,EAAEF,MAAM,CAACE,SAAS;MAC3BH,OAAO,EAAEC,MAAM,CAACD,OAAO;MACvBI,IAAI,EAAEH,MAAM,CAACG;IACjB,CAAC,CACJ;EACL;EAEA,OAAOH,MAAM,CAACD,OAAO;AACzB,CAAC;AAAC"}
@@ -0,0 +1,2 @@
1
+ import { CmsModelField } from "../../../types";
2
+ export declare const getContentModelTitleFieldId: (fields: CmsModelField[], titleFieldId?: string) => string;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getContentModelTitleFieldId = void 0;
8
+ var _getBaseFieldType = require("../../../utils/getBaseFieldType");
9
+ var _error = _interopRequireDefault(require("@webiny/error"));
10
+ const defaultTitleFieldId = "id";
11
+ const allowedTitleFieldTypes = ["text", "number"];
12
+ const getContentModelTitleFieldId = (fields, titleFieldId) => {
13
+ /**
14
+ * If there are no fields defined, we will return the default field
15
+ */
16
+ if (fields.length === 0) {
17
+ return defaultTitleFieldId;
18
+ }
19
+ /**
20
+ * if there is no title field defined either in input data or existing content model data
21
+ * we will take first text field that has no multiple values enabled
22
+ * or if initial titleFieldId is the default one also try to find first available text field
23
+ */
24
+ if (!titleFieldId || titleFieldId === defaultTitleFieldId) {
25
+ const titleField = fields.find(field => {
26
+ return (0, _getBaseFieldType.getBaseFieldType)(field) === "text" && !field.multipleValues;
27
+ });
28
+ return (titleField === null || titleField === void 0 ? void 0 : titleField.fieldId) || defaultTitleFieldId;
29
+ }
30
+ /**
31
+ * check existing titleFieldId for existence in the model
32
+ * for correct type
33
+ * and that it is not multiple values field
34
+ */
35
+ const target = fields.find(f => f.fieldId === titleFieldId);
36
+ if (!target) {
37
+ throw new _error.default(`Field selected for the title field does not exist in the model.`, "VALIDATION_ERROR", {
38
+ fieldId: titleFieldId,
39
+ fields
40
+ });
41
+ }
42
+ if (allowedTitleFieldTypes.includes(target.type) === false) {
43
+ throw new _error.default(`Only ${allowedTitleFieldTypes.join(", ")} and id fields can be used as an entry title.`, "ENTRY_TITLE_FIELD_TYPE", {
44
+ storageId: target.storageId,
45
+ fieldId: target.fieldId,
46
+ type: target.type
47
+ });
48
+ }
49
+ if (target.multipleValues) {
50
+ throw new _error.default(`Fields that accept multiple values cannot be used as the entry title.`, "ENTRY_TITLE_FIELD_TYPE", {
51
+ storageId: target.storageId,
52
+ fieldId: target.fieldId,
53
+ type: target.type
54
+ });
55
+ }
56
+ return target.fieldId;
57
+ };
58
+ exports.getContentModelTitleFieldId = getContentModelTitleFieldId;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["defaultTitleFieldId","allowedTitleFieldTypes","getContentModelTitleFieldId","fields","titleFieldId","length","titleField","find","field","getBaseFieldType","multipleValues","fieldId","target","f","WebinyError","includes","type","join","storageId"],"sources":["titleField.ts"],"sourcesContent":["import { CmsModelField } from \"~/types\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\nimport WebinyError from \"@webiny/error\";\n\nconst defaultTitleFieldId = \"id\";\n\nconst allowedTitleFieldTypes = [\"text\", \"number\"];\n\nexport const getContentModelTitleFieldId = (\n fields: CmsModelField[],\n titleFieldId?: string\n): string => {\n /**\n * If there are no fields defined, we will return the default field\n */\n if (fields.length === 0) {\n return defaultTitleFieldId;\n }\n /**\n * if there is no title field defined either in input data or existing content model data\n * we will take first text field that has no multiple values enabled\n * or if initial titleFieldId is the default one also try to find first available text field\n */\n if (!titleFieldId || titleFieldId === defaultTitleFieldId) {\n const titleField = fields.find(field => {\n return getBaseFieldType(field) === \"text\" && !field.multipleValues;\n });\n return titleField?.fieldId || defaultTitleFieldId;\n }\n /**\n * check existing titleFieldId for existence in the model\n * for correct type\n * and that it is not multiple values field\n */\n const target = fields.find(f => f.fieldId === titleFieldId);\n if (!target) {\n throw new WebinyError(\n `Field selected for the title field does not exist in the model.`,\n \"VALIDATION_ERROR\",\n {\n fieldId: titleFieldId,\n fields\n }\n );\n }\n\n if (allowedTitleFieldTypes.includes(target.type) === false) {\n throw new WebinyError(\n `Only ${allowedTitleFieldTypes.join(\n \", \"\n )} and id fields can be used as an entry title.`,\n \"ENTRY_TITLE_FIELD_TYPE\",\n {\n storageId: target.storageId,\n fieldId: target.fieldId,\n type: target.type\n }\n );\n }\n\n if (target.multipleValues) {\n throw new WebinyError(\n `Fields that accept multiple values cannot be used as the entry title.`,\n \"ENTRY_TITLE_FIELD_TYPE\",\n {\n storageId: target.storageId,\n fieldId: target.fieldId,\n type: target.type\n }\n );\n }\n\n return target.fieldId;\n};\n"],"mappings":";;;;;;;AACA;AACA;AAEA,MAAMA,mBAAmB,GAAG,IAAI;AAEhC,MAAMC,sBAAsB,GAAG,CAAC,MAAM,EAAE,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SAAS;MAC3BP,OAAO,EAAEC,MAAM,CAACD,OAAO;MACvBK,IAAI,EAAEJ,MAAM,CAACI;IACjB,CAAC,CACJ;EACL;EAEA,OAAOJ,MAAM,CAACD,OAAO;AACzB,CAAC;AAAC"}
@@ -1 +1 @@
1
- {"version":3,"names":["fieldSystemFields"],"sources":["systemFields.ts"],"sourcesContent":["export const fieldSystemFields: string[] = [\n \"id\",\n \"fieldId\",\n \"storageId\",\n \"label\",\n \"helpText\",\n \"placeholderText\",\n \"type\",\n \"multipleValues\",\n \"predefinedValues\",\n \"renderer\",\n \"validation\",\n \"listValidation\",\n \"settings\"\n];\n"],"mappings":";;;;;;AAAO,MAAMA,iBAA2B,GAAG,CACvC,IAAI,EACJ,SAAS,EACT,WAAW,EACX,OAAO,EACP,UAAU,EACV,iBAAiB,EACjB,MAAM,EACN,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,YAAY,EACZ,gBAAgB,EAChB,UAAU,CACb;AAAC"}
1
+ {"version":3,"names":["fieldSystemFields"],"sources":["systemFields.ts"],"sourcesContent":["export const fieldSystemFields: string[] = [\n \"id\",\n \"fieldId\",\n \"storageId\",\n \"label\",\n \"helpText\",\n \"placeholderText\",\n \"type\",\n \"multipleValues\",\n \"predefinedValues\",\n \"renderer\",\n \"validation\",\n \"listValidation\",\n \"settings\"\n];\n"],"mappings":";;;;;;AAAO,MAAMA,iBAA2B,GAAG,CACvC,IADuC,EAEvC,SAFuC,EAGvC,WAHuC,EAIvC,OAJuC,EAKvC,UALuC,EAMvC,iBANuC,EAOvC,MAPuC,EAQvC,gBARuC,EASvC,kBATuC,EAUvC,UAVuC,EAWvC,YAXuC,EAYvC,gBAZuC,EAavC,UAbuC,CAApC"}
@@ -1,5 +1,6 @@
1
1
  import { CmsContext, CmsModel } from "../../types";
2
2
  interface ValidateModelParams {
3
+ models: CmsModel[];
3
4
  model: CmsModel;
4
5
  original?: CmsModel;
5
6
  context: CmsContext;
@@ -1 +1 @@
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,MAA2B,IAAoB;EAC/E,MAAM;IAAEC,KAAK;IAAEC;EAAQ,CAAC,GAAGF,MAAM;EAEjC,MAAM;IAAEG;EAAQ,CAAC,GAAGD,OAAO;EAE3B,MAAME,WAAW,GAAGD,OAAO,CACtBE,MAAM,CAAiBC,8BAAc,CAACC,IAAI,CAAC,CAC3CC,IAAI,CAACC,IAAI,IAAIA,IAAI,CAACC,YAAY,CAACC,OAAO,KAAKV,KAAK,CAACU,OAAO,CAAC;EAE9D,IAAIP,WAAW,EAAE;IACb,MAAM,IAAIQ,cAAW,CACjB,uDAAuD,EACvD,4BAA4B,EAC5B;MACID,OAAO,EAAEV,KAAK,CAACU;IACnB,CAAC,CACJ;EACL;EAEA,MAAM,IAAAE,wCAAmB,EAACb,MAAM,CAAC;AACrC,CAAC;AAAC"}
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 models: CmsModel[];\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;AASO,MAAMA,aAAa,GAAG,MAAOC,MAA2B,IAAoB;EAC/E,MAAM;IAAEC,KAAK;IAAEC;EAAQ,CAAC,GAAGF,MAAM;EAEjC,MAAM;IAAEG;EAAQ,CAAC,GAAGD,OAAO;EAE3B,MAAME,WAAW,GAAGD,OAAO,CACtBE,MAAM,CAAiBC,8BAAc,CAACC,IAAI,CAAC,CAC3CC,IAAI,CAACC,IAAI,IAAIA,IAAI,CAACC,YAAY,CAACC,OAAO,KAAKV,KAAK,CAACU,OAAO,CAAC;EAE9D,IAAIP,WAAW,EAAE;IACb,MAAM,IAAIQ,cAAW,CACjB,uDAAuD,EACvD,4BAA4B,EAC5B;MACID,OAAO,EAAEV,KAAK,CAACU;IACnB,CAAC,CACJ;EACL;EAEA,MAAM,IAAAE,wCAAmB,EAACb,MAAM,CAAC;AACrC,CAAC;AAAC"}
@@ -1,5 +1,6 @@
1
- import { CmsContext, CmsModel } from "../../types";
1
+ import { CmsModel, CmsContext } from "../../types";
2
2
  interface ValidateModelFieldsParams {
3
+ models: CmsModel[];
3
4
  model: CmsModel;
4
5
  original?: CmsModel;
5
6
  context: CmsContext;
@@ -6,64 +6,18 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.validateModelFields = void 0;
8
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
9
10
  var _error = _interopRequireDefault(require("@webiny/error"));
10
11
  var _createManageSDL = require("../../graphql/schema/createManageSDL");
11
- var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
12
12
  var _createFieldStorageId = require("./createFieldStorageId");
13
13
  var _getBaseFieldType = require("../../utils/getBaseFieldType");
14
+ var _titleField = require("./fields/titleField");
15
+ var _descriptionField = require("./fields/descriptionField");
16
+ var _imageField = require("./fields/imageField");
14
17
  var _plugins = require("../../plugins");
15
18
  var _buildSchemaPlugins = require("../../graphql/buildSchemaPlugins");
16
19
  var _createExecutableSchema = require("../../graphql/createExecutableSchema");
17
- var _handlerGraphql = require("@webiny/handler-graphql");
18
20
  var _utils = require("@webiny/utils");
19
- const defaultTitleFieldId = "id";
20
- const allowedTitleFieldTypes = ["text", "number"];
21
- const getContentModelTitleFieldId = (fields, titleFieldId) => {
22
- /**
23
- * If there are no fields defined, we will return the default field
24
- */
25
- if (fields.length === 0) {
26
- return defaultTitleFieldId;
27
- }
28
- /**
29
- * if there is no title field defined either in input data or existing content model data
30
- * we will take first text field that has no multiple values enabled
31
- * or if initial titleFieldId is the default one also try to find first available text field
32
- */
33
- if (!titleFieldId || titleFieldId === defaultTitleFieldId) {
34
- const titleField = fields.find(field => {
35
- return (0, _getBaseFieldType.getBaseFieldType)(field) === "text" && !field.multipleValues;
36
- });
37
- return (titleField === null || titleField === void 0 ? void 0 : titleField.fieldId) || defaultTitleFieldId;
38
- }
39
- /**
40
- * check existing titleFieldId for existence in the model
41
- * for correct type
42
- * and that it is not multiple values field
43
- */
44
- const target = fields.find(f => f.fieldId === titleFieldId);
45
- if (!target) {
46
- throw new _error.default(`Field selected for the title field does not exist in the model.`, "VALIDATION_ERROR", {
47
- fieldId: titleFieldId,
48
- fields
49
- });
50
- }
51
- if (allowedTitleFieldTypes.includes(target.type) === false) {
52
- throw new _error.default(`Only ${allowedTitleFieldTypes.join(", ")} and id fields can be used as an entry title.`, "ENTRY_TITLE_FIELD_TYPE", {
53
- storageId: target.storageId,
54
- fieldId: target.fieldId,
55
- type: target.type
56
- });
57
- }
58
- if (target.multipleValues) {
59
- throw new _error.default(`Fields that accept multiple values cannot be used as the entry title.`, "ENTRY_TITLE_FIELD_TYPE", {
60
- storageId: target.storageId,
61
- fieldId: target.fieldId,
62
- type: target.type
63
- });
64
- }
65
- return target.fieldId;
66
- };
67
21
  const extractInvalidField = (model, err) => {
68
22
  var _err$source;
69
23
  const sdl = ((_err$source = err.source) === null || _err$source === void 0 ? void 0 : _err$source.body) || "";
@@ -234,14 +188,16 @@ const createGraphQLSchema = async params => {
234
188
  model
235
189
  } = params;
236
190
  context.security.disableAuthorization();
237
- const models = await context.cms.listModels();
191
+ const models = (await context.cms.listModels()).filter(model => {
192
+ return !model.isPrivate;
193
+ });
238
194
  context.security.enableAuthorization();
239
195
  const modelPlugins = await (0, _buildSchemaPlugins.buildSchemaPlugins)({
240
196
  context,
241
197
  models: models.concat([model])
242
198
  });
243
- const plugins = context.plugins.byType(_handlerGraphql.GraphQLSchemaPlugin.type).reduce((collection, plugin) => {
244
- 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)}`;
245
201
  collection[name] = plugin;
246
202
  return collection;
247
203
  }, {});
@@ -264,12 +220,15 @@ const extractErrorObject = error => {
264
220
  };
265
221
  const validateModelFields = async params => {
266
222
  const {
223
+ models,
267
224
  model,
268
225
  original,
269
226
  context
270
227
  } = params;
271
228
  const {
272
- titleFieldId
229
+ titleFieldId,
230
+ descriptionFieldId,
231
+ imageFieldId
273
232
  } = model;
274
233
  const {
275
234
  plugins
@@ -300,6 +259,7 @@ const validateModelFields = async params => {
300
259
  * Make sure that this model can be safely converted to a GraphQL SDL
301
260
  */
302
261
  const schema = (0, _createManageSDL.createManageSDL)({
262
+ models,
303
263
  model,
304
264
  fieldTypePlugins: fieldTypePlugins.reduce((acc, pl) => (0, _objectSpread2.default)((0, _objectSpread2.default)({}, acc), {}, {
305
265
  [pl.fieldType]: pl
@@ -330,7 +290,9 @@ const validateModelFields = async params => {
330
290
  });
331
291
  }
332
292
  }
333
- model.titleFieldId = getContentModelTitleFieldId(fields, titleFieldId);
293
+ model.titleFieldId = (0, _titleField.getContentModelTitleFieldId)(fields, titleFieldId);
294
+ model.descriptionFieldId = (0, _descriptionField.getContentModelDescriptionFieldId)(fields, descriptionFieldId);
295
+ model.imageFieldId = (0, _imageField.getContentModelImageFieldId)(fields, imageFieldId);
334
296
  const cmsLockedFieldPlugins = plugins.byType("cms-model-locked-field");
335
297
 
336
298
  /**