@webiny/api-headless-cms 0.0.0-unstable.d7f521b032 → 0.0.0-unstable.de38392959
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.
- package/constants.d.ts +32 -0
- package/constants.js +57 -0
- package/constants.js.map +1 -0
- package/context.js +88 -47
- package/context.js.map +1 -1
- package/crud/contentEntry/afterDelete.js +3 -1
- package/crud/contentEntry/afterDelete.js.map +1 -1
- package/crud/contentEntry/beforeCreate.js +3 -1
- package/crud/contentEntry/beforeCreate.js.map +1 -1
- package/crud/contentEntry/beforeUpdate.js +3 -1
- package/crud/contentEntry/beforeUpdate.js.map +1 -1
- package/crud/contentEntry/entryDataFactories/createEntryData.d.ts +20 -0
- package/crud/contentEntry/entryDataFactories/createEntryData.js +228 -0
- package/crud/contentEntry/entryDataFactories/createEntryData.js.map +1 -0
- package/crud/contentEntry/entryDataFactories/createEntryRevisionFromData.d.ts +21 -0
- package/crud/contentEntry/entryDataFactories/createEntryRevisionFromData.js +114 -0
- package/crud/contentEntry/entryDataFactories/createEntryRevisionFromData.js.map +1 -0
- package/crud/contentEntry/entryDataFactories/createPublishEntryData.d.ts +13 -0
- package/crud/contentEntry/entryDataFactories/createPublishEntryData.js +61 -0
- package/crud/contentEntry/entryDataFactories/createPublishEntryData.js.map +1 -0
- package/crud/contentEntry/entryDataFactories/createRepublishEntryData.d.ts +12 -0
- package/crud/contentEntry/entryDataFactories/createRepublishEntryData.js +57 -0
- package/crud/contentEntry/entryDataFactories/createRepublishEntryData.js.map +1 -0
- package/crud/contentEntry/entryDataFactories/createUnpublishEntryData.d.ts +12 -0
- package/crud/contentEntry/entryDataFactories/createUnpublishEntryData.js +38 -0
- package/crud/contentEntry/entryDataFactories/createUnpublishEntryData.js.map +1 -0
- package/crud/contentEntry/entryDataFactories/createUpdateEntryData.d.ts +20 -0
- package/crud/contentEntry/entryDataFactories/createUpdateEntryData.js +122 -0
- package/crud/contentEntry/entryDataFactories/createUpdateEntryData.js.map +1 -0
- package/crud/contentEntry/entryDataFactories/index.d.ts +8 -0
- package/crud/contentEntry/entryDataFactories/index.js +95 -0
- package/crud/contentEntry/entryDataFactories/index.js.map +1 -0
- package/crud/contentEntry/entryDataFactories/mapAndCleanUpdatedInputData.d.ts +5 -0
- package/crud/contentEntry/entryDataFactories/mapAndCleanUpdatedInputData.js +36 -0
- package/crud/contentEntry/entryDataFactories/mapAndCleanUpdatedInputData.js.map +1 -0
- package/crud/contentEntry/entryDataFactories/statuses.d.ts +4 -0
- package/crud/contentEntry/entryDataFactories/statuses.js +15 -0
- package/crud/contentEntry/entryDataFactories/statuses.js.map +1 -0
- package/crud/contentEntry/entryDataValidation.d.ts +4 -2
- package/crud/contentEntry/entryDataValidation.js +223 -45
- package/crud/contentEntry/entryDataValidation.js.map +1 -1
- package/crud/contentEntry/markLockedFields.d.ts +1 -1
- package/crud/contentEntry/markLockedFields.js +20 -10
- package/crud/contentEntry/markLockedFields.js.map +1 -1
- package/crud/contentEntry/referenceFieldsMapping.d.ts +6 -0
- package/crud/contentEntry/referenceFieldsMapping.js +142 -90
- package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
- package/crud/contentEntry/searchableFields.js +5 -4
- package/crud/contentEntry/searchableFields.js.map +1 -1
- package/crud/contentEntry.crud.d.ts +9 -5
- package/crud/contentEntry.crud.js +1093 -981
- package/crud/contentEntry.crud.js.map +1 -1
- package/crud/contentModel/beforeCreate.d.ts +1 -1
- package/crud/contentModel/beforeCreate.js +50 -85
- package/crud/contentModel/beforeCreate.js.map +1 -1
- package/crud/contentModel/beforeDelete.d.ts +1 -1
- package/crud/contentModel/beforeDelete.js +4 -6
- package/crud/contentModel/beforeDelete.js.map +1 -1
- package/crud/contentModel/beforeUpdate.d.ts +1 -1
- package/crud/contentModel/beforeUpdate.js +31 -6
- package/crud/contentModel/beforeUpdate.js.map +1 -1
- package/crud/contentModel/compatibility/modelApiName.d.ts +3 -0
- package/crud/contentModel/compatibility/modelApiName.js +26 -0
- package/crud/contentModel/compatibility/modelApiName.js.map +1 -0
- package/crud/contentModel/contentModelManagerFactory.js +3 -1
- package/crud/contentModel/contentModelManagerFactory.js.map +1 -1
- package/crud/contentModel/createFieldStorageId.js +3 -1
- package/crud/contentModel/createFieldStorageId.js.map +1 -1
- package/crud/contentModel/defaultFields.d.ts +5 -0
- package/crud/contentModel/defaultFields.js +60 -0
- package/crud/contentModel/defaultFields.js.map +1 -0
- package/crud/contentModel/ensureTypeTag.d.ts +5 -0
- package/crud/contentModel/ensureTypeTag.js +21 -0
- package/crud/contentModel/ensureTypeTag.js.map +1 -0
- package/crud/contentModel/fields/descriptionField.d.ts +2 -0
- package/crud/contentModel/fields/descriptionField.js +44 -0
- package/crud/contentModel/fields/descriptionField.js.map +1 -0
- package/crud/contentModel/fields/imageField.d.ts +2 -0
- package/crud/contentModel/fields/imageField.js +44 -0
- package/crud/contentModel/fields/imageField.js.map +1 -0
- package/crud/contentModel/fields/titleField.d.ts +2 -0
- package/crud/contentModel/fields/titleField.js +60 -0
- package/crud/contentModel/fields/titleField.js.map +1 -0
- package/crud/contentModel/listModelsFromDatabase.d.ts +10 -0
- package/crud/contentModel/listModelsFromDatabase.js +38 -0
- package/crud/contentModel/listModelsFromDatabase.js.map +1 -0
- package/crud/contentModel/validate/endingAllowed.d.ts +6 -0
- package/crud/contentModel/validate/endingAllowed.js +28 -0
- package/crud/contentModel/validate/endingAllowed.js.map +1 -0
- package/crud/contentModel/validate/isModelEndingAllowed.d.ts +6 -0
- package/crud/contentModel/validate/isModelEndingAllowed.js +26 -0
- package/crud/contentModel/validate/isModelEndingAllowed.js.map +1 -0
- package/crud/contentModel/validate/modelId.d.ts +11 -0
- package/crud/contentModel/validate/modelId.js +38 -0
- package/crud/contentModel/validate/modelId.js.map +1 -0
- package/crud/contentModel/validate/pluralApiName.d.ts +7 -0
- package/crud/contentModel/validate/pluralApiName.js +26 -0
- package/crud/contentModel/validate/pluralApiName.js.map +1 -0
- package/crud/contentModel/validate/singularApiName.d.ts +7 -0
- package/crud/contentModel/validate/singularApiName.js +26 -0
- package/crud/contentModel/validate/singularApiName.js.map +1 -0
- package/crud/contentModel/validateModel.d.ts +1 -0
- package/crud/contentModel/validateModel.js +3 -1
- package/crud/contentModel/validateModel.js.map +1 -1
- package/crud/contentModel/validateModelFields.d.ts +2 -1
- package/crud/contentModel/validateModelFields.js +27 -64
- package/crud/contentModel/validateModelFields.js.map +1 -1
- package/crud/contentModel/validation.d.ts +595 -200
- package/crud/contentModel/validation.js +125 -17
- package/crud/contentModel/validation.js.map +1 -1
- package/crud/contentModel.crud.d.ts +2 -0
- package/crud/contentModel.crud.js +437 -411
- package/crud/contentModel.crud.js.map +1 -1
- package/crud/contentModelGroup/beforeCreate.d.ts +1 -1
- package/crud/contentModelGroup/beforeCreate.js +15 -1
- package/crud/contentModelGroup/beforeCreate.js.map +1 -1
- package/crud/contentModelGroup/beforeDelete.js +3 -1
- package/crud/contentModelGroup/beforeDelete.js.map +1 -1
- package/crud/contentModelGroup/beforeUpdate.js +3 -1
- package/crud/contentModelGroup/beforeUpdate.js.map +1 -1
- package/crud/contentModelGroup/listGroupsFromDatabase.d.ts +8 -0
- package/crud/contentModelGroup/listGroupsFromDatabase.js +22 -0
- package/crud/contentModelGroup/listGroupsFromDatabase.js.map +1 -0
- package/crud/contentModelGroup/validation.d.ts +10 -7
- package/crud/contentModelGroup/validation.js +5 -2
- package/crud/contentModelGroup/validation.js.map +1 -1
- package/crud/contentModelGroup.crud.d.ts +3 -1
- package/crud/contentModelGroup.crud.js +272 -228
- package/crud/contentModelGroup.crud.js.map +1 -1
- package/crud/system.crud.js +8 -71
- package/crud/system.crud.js.map +1 -1
- package/export/crud/exporting.d.ts +3 -0
- package/export/crud/exporting.js +49 -0
- package/export/crud/exporting.js.map +1 -0
- package/export/crud/importing.d.ts +3 -0
- package/export/crud/importing.js +79 -0
- package/export/crud/importing.js.map +1 -0
- package/export/crud/imports/importData.d.ts +14 -0
- package/export/crud/imports/importData.js +52 -0
- package/export/crud/imports/importData.js.map +1 -0
- package/export/crud/imports/importGroups.d.ts +8 -0
- package/export/crud/imports/importGroups.js +104 -0
- package/export/crud/imports/importGroups.js.map +1 -0
- package/export/crud/imports/importModels.d.ts +8 -0
- package/export/crud/imports/importModels.js +136 -0
- package/export/crud/imports/importModels.js.map +1 -0
- package/export/crud/imports/validateGroups.d.ts +8 -0
- package/export/crud/imports/validateGroups.js +112 -0
- package/export/crud/imports/validateGroups.js.map +1 -0
- package/export/crud/imports/validateInput.d.ts +19 -0
- package/export/crud/imports/validateInput.js +55 -0
- package/export/crud/imports/validateInput.js.map +1 -0
- package/export/crud/imports/validateModels.d.ts +12 -0
- package/export/crud/imports/validateModels.js +203 -0
- package/export/crud/imports/validateModels.js.map +1 -0
- package/export/crud/index.d.ts +4 -0
- package/export/crud/index.js +15 -0
- package/export/crud/index.js.map +1 -0
- package/export/crud/sanitize.d.ts +4 -0
- package/export/crud/sanitize.js +35 -0
- package/export/crud/sanitize.js.map +1 -0
- package/export/graphql/index.d.ts +3 -0
- package/export/graphql/index.js +188 -0
- package/export/graphql/index.js.map +1 -0
- package/export/index.d.ts +2 -0
- package/export/index.js +29 -0
- package/export/index.js.map +1 -0
- package/export/types.d.ts +113 -0
- package/export/types.js +22 -0
- package/export/types.js.map +1 -0
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +4 -7
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +5 -8
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +47 -38
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/index.js +3 -1
- package/fieldConverters/index.js.map +1 -1
- package/graphql/buildSchemaPlugins.js +7 -1
- package/graphql/buildSchemaPlugins.js.map +1 -1
- package/graphql/checkEndpointAccess.d.ts +2 -0
- package/graphql/checkEndpointAccess.js +20 -0
- package/graphql/checkEndpointAccess.js.map +1 -0
- package/graphql/createExecutableSchema.d.ts +2 -3
- package/graphql/createExecutableSchema.js +3 -1
- package/graphql/createExecutableSchema.js.map +1 -1
- package/graphql/createRequestBody.d.ts +2 -0
- package/graphql/createRequestBody.js +16 -0
- package/graphql/createRequestBody.js.map +1 -0
- package/graphql/formatErrorPayload.d.ts +1 -0
- package/graphql/formatErrorPayload.js +27 -0
- package/graphql/formatErrorPayload.js.map +1 -0
- package/graphql/generateSchema.js +3 -1
- package/graphql/generateSchema.js.map +1 -1
- package/graphql/getSchema.d.ts +16 -0
- package/graphql/getSchema.js +118 -0
- package/graphql/getSchema.js.map +1 -0
- package/graphql/graphQLHandlerFactory.js +9 -146
- package/graphql/graphQLHandlerFactory.js.map +1 -1
- package/graphql/handleRequest.d.ts +11 -0
- package/graphql/handleRequest.js +79 -0
- package/graphql/handleRequest.js.map +1 -0
- package/graphql/index.d.ts +1 -1
- package/graphql/index.js +4 -2
- package/graphql/index.js.map +1 -1
- package/graphql/schema/baseContentSchema.js +10 -15
- package/graphql/schema/baseContentSchema.js.map +1 -1
- package/graphql/schema/baseSchema.d.ts +2 -3
- package/graphql/schema/baseSchema.js +95 -2
- package/graphql/schema/baseSchema.js.map +1 -1
- package/graphql/schema/contentEntries.js +134 -59
- package/graphql/schema/contentEntries.js.map +1 -1
- package/graphql/schema/contentModelGroups.js +12 -9
- package/graphql/schema/contentModelGroups.js.map +1 -1
- package/graphql/schema/contentModels.js +33 -14
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createFieldResolvers.d.ts +1 -1
- package/graphql/schema/createFieldResolvers.js +18 -22
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/graphql/schema/createFieldTypePluginRecords.d.ts +3 -0
- package/graphql/schema/createFieldTypePluginRecords.js +15 -0
- package/graphql/schema/createFieldTypePluginRecords.js.map +1 -0
- package/graphql/schema/createManageResolvers.d.ts +1 -1
- package/graphql/schema/createManageResolvers.js +60 -27
- package/graphql/schema/createManageResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.d.ts +1 -0
- package/graphql/schema/createManageSDL.js +116 -69
- package/graphql/schema/createManageSDL.js.map +1 -1
- package/graphql/schema/createPreviewResolvers.js +10 -13
- package/graphql/schema/createPreviewResolvers.js.map +1 -1
- package/graphql/schema/createReadResolvers.js +11 -14
- package/graphql/schema/createReadResolvers.js.map +1 -1
- package/graphql/schema/createReadSDL.d.ts +1 -0
- package/graphql/schema/createReadSDL.js +51 -38
- package/graphql/schema/createReadSDL.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveCreate.d.ts +2 -1
- package/graphql/schema/resolvers/manage/resolveCreate.js +4 -2
- package/graphql/schema/resolvers/manage/resolveCreate.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveCreateFrom.d.ts +2 -1
- package/graphql/schema/resolvers/manage/resolveCreateFrom.js +4 -2
- package/graphql/schema/resolvers/manage/resolveCreateFrom.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveDelete.d.ts +2 -1
- package/graphql/schema/resolvers/manage/resolveDelete.js +16 -4
- package/graphql/schema/resolvers/manage/resolveDelete.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveDeleteMultiple.d.ts +7 -0
- package/graphql/schema/resolvers/manage/resolveDeleteMultiple.js +22 -0
- package/graphql/schema/resolvers/manage/resolveDeleteMultiple.js.map +1 -0
- package/graphql/schema/resolvers/manage/resolveGet.js +12 -5
- package/graphql/schema/resolvers/manage/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGetByIds.js +3 -1
- package/graphql/schema/resolvers/manage/resolveGetByIds.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGetRevisions.js +3 -1
- package/graphql/schema/resolvers/manage/resolveGetRevisions.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGetUniqueFieldValues.d.ts +4 -0
- package/graphql/schema/resolvers/manage/resolveGetUniqueFieldValues.js +20 -0
- package/graphql/schema/resolvers/manage/resolveGetUniqueFieldValues.js.map +1 -0
- package/graphql/schema/resolvers/manage/resolveList.js +3 -1
- package/graphql/schema/resolvers/manage/resolveList.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveMove.d.ts +8 -0
- package/graphql/schema/resolvers/manage/resolveMove.js +27 -0
- package/graphql/schema/resolvers/manage/resolveMove.js.map +1 -0
- package/graphql/schema/resolvers/manage/resolvePublish.js +3 -1
- package/graphql/schema/resolvers/manage/resolvePublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveRepublish.js +3 -1
- package/graphql/schema/resolvers/manage/resolveRepublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveUnpublish.js +3 -1
- package/graphql/schema/resolvers/manage/resolveUnpublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveUpdate.d.ts +2 -1
- package/graphql/schema/resolvers/manage/resolveUpdate.js +4 -2
- package/graphql/schema/resolvers/manage/resolveUpdate.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveValidate.d.ts +8 -0
- package/graphql/schema/resolvers/manage/resolveValidate.js +20 -0
- package/graphql/schema/resolvers/manage/resolveValidate.js.map +1 -0
- package/graphql/schema/resolvers/preview/resolveGet.js +6 -5
- package/graphql/schema/resolvers/preview/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/preview/resolveList.js +3 -1
- package/graphql/schema/resolvers/preview/resolveList.js.map +1 -1
- package/graphql/schema/resolvers/read/resolveGet.js +6 -5
- package/graphql/schema/resolvers/read/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/read/resolveList.js +3 -1
- package/graphql/schema/resolvers/read/resolveList.js.map +1 -1
- package/graphql/schema/schemaPlugins.js +10 -17
- package/graphql/schema/schemaPlugins.js.map +1 -1
- package/graphql/system.d.ts +2 -5
- package/graphql/system.js +4 -28
- package/graphql/system.js.map +1 -1
- package/graphqlFields/boolean.js +3 -1
- package/graphqlFields/boolean.js.map +1 -1
- package/graphqlFields/datetime.js +5 -5
- package/graphqlFields/datetime.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.js +86 -28
- package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js +60 -12
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js.map +1 -1
- package/graphqlFields/dynamicZone/index.js +3 -1
- package/graphqlFields/dynamicZone/index.js.map +1 -1
- package/graphqlFields/file.js +3 -1
- package/graphqlFields/file.js.map +1 -1
- package/graphqlFields/helpers.d.ts +0 -1
- package/graphqlFields/helpers.js +6 -18
- package/graphqlFields/helpers.js.map +1 -1
- package/graphqlFields/index.js +5 -2
- package/graphqlFields/index.js.map +1 -1
- package/graphqlFields/json.d.ts +2 -0
- package/graphqlFields/json.js +49 -0
- package/graphqlFields/json.js.map +1 -0
- package/graphqlFields/longText.js +14 -3
- package/graphqlFields/longText.js.map +1 -1
- package/graphqlFields/number.js +4 -1
- package/graphqlFields/number.js.map +1 -1
- package/graphqlFields/object.js +33 -34
- package/graphqlFields/object.js.map +1 -1
- package/graphqlFields/ref.js +68 -28
- package/graphqlFields/ref.js.map +1 -1
- package/graphqlFields/richText/RichTextPluginsProcessor.d.ts +6 -0
- package/graphqlFields/richText/RichTextPluginsProcessor.js +34 -0
- package/graphqlFields/richText/RichTextPluginsProcessor.js.map +1 -0
- package/graphqlFields/richText/richTextResolver.d.ts +7 -0
- package/graphqlFields/richText/richTextResolver.js +39 -0
- package/graphqlFields/richText/richTextResolver.js.map +1 -0
- package/graphqlFields/richText.js +11 -3
- package/graphqlFields/richText.js.map +1 -1
- package/graphqlFields/text.js +5 -1
- package/graphqlFields/text.js.map +1 -1
- package/htmlRenderer/LexicalRenderer.d.ts +5 -0
- package/htmlRenderer/LexicalRenderer.js +28 -0
- package/htmlRenderer/LexicalRenderer.js.map +1 -0
- package/htmlRenderer/createLexicalHTMLRenderer.d.ts +2 -0
- package/htmlRenderer/createLexicalHTMLRenderer.js +31 -0
- package/htmlRenderer/createLexicalHTMLRenderer.js.map +1 -0
- package/index.d.ts +5 -2
- package/index.js +44 -6
- package/index.js.map +1 -1
- package/modelManager/DefaultCmsModelManager.js +3 -5
- package/modelManager/DefaultCmsModelManager.js.map +1 -1
- package/modelManager/index.js +3 -1
- package/modelManager/index.js.map +1 -1
- package/package.json +36 -40
- package/parameters/context.js +4 -2
- package/parameters/context.js.map +1 -1
- package/parameters/header.js +7 -6
- package/parameters/header.js.map +1 -1
- package/parameters/index.js +3 -1
- package/parameters/index.js.map +1 -1
- package/parameters/manual.js +9 -4
- package/parameters/manual.js.map +1 -1
- package/parameters/path.js +4 -3
- package/parameters/path.js.map +1 -1
- package/plugins/CmsGraphQLSchemaPlugin.js +5 -4
- package/plugins/CmsGraphQLSchemaPlugin.js.map +1 -1
- package/plugins/CmsGraphQLSchemaSorterPlugin.js +4 -5
- package/plugins/CmsGraphQLSchemaSorterPlugin.js.map +1 -1
- package/plugins/CmsGroupPlugin.d.ts +6 -3
- package/plugins/CmsGroupPlugin.js +8 -6
- package/plugins/CmsGroupPlugin.js.map +1 -1
- package/plugins/CmsModelFieldConverterPlugin.js +5 -4
- package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
- package/plugins/CmsModelPlugin.d.ts +25 -5
- package/plugins/CmsModelPlugin.js +75 -20
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/plugins/CmsParametersPlugin.js +7 -4
- package/plugins/CmsParametersPlugin.js.map +1 -1
- package/plugins/CmsRichTextRendererPlugin.d.ts +24 -0
- package/plugins/CmsRichTextRendererPlugin.js +28 -0
- package/plugins/CmsRichTextRendererPlugin.js.map +1 -0
- package/plugins/StorageOperationsCmsModelPlugin.d.ts +23 -0
- package/plugins/StorageOperationsCmsModelPlugin.js +41 -0
- package/plugins/StorageOperationsCmsModelPlugin.js.map +1 -0
- package/plugins/StorageTransformPlugin.d.ts +2 -2
- package/plugins/StorageTransformPlugin.js +3 -4
- package/plugins/StorageTransformPlugin.js.map +1 -1
- package/plugins/index.d.ts +2 -0
- package/plugins/index.js +25 -1
- package/plugins/index.js.map +1 -1
- package/storage/default.js +3 -1
- package/storage/default.js.map +1 -1
- package/storage/index.d.ts +1 -0
- package/storage/index.js +15 -0
- package/storage/index.js.map +1 -0
- package/storage/json.d.ts +2 -0
- package/storage/json.js +27 -0
- package/storage/json.js.map +1 -0
- package/storage/object.js +8 -8
- package/storage/object.js.map +1 -1
- package/types.d.ts +510 -334
- package/types.js +21 -21
- package/types.js.map +1 -1
- package/utils/access.d.ts +9 -8
- package/utils/access.js +12 -62
- package/utils/access.js.map +1 -1
- package/utils/caching/Cache.d.ts +2 -0
- package/utils/caching/Cache.js +51 -0
- package/utils/caching/Cache.js.map +1 -0
- package/utils/caching/CacheKey.d.ts +2 -0
- package/utils/caching/CacheKey.js +40 -0
- package/utils/caching/CacheKey.js.map +1 -0
- package/utils/caching/index.d.ts +2 -0
- package/utils/caching/index.js +29 -0
- package/utils/caching/index.js.map +1 -0
- package/utils/caching/types.d.ts +11 -0
- package/utils/caching/types.js +7 -0
- package/utils/caching/types.js.map +1 -0
- package/utils/converters/Converter.js +4 -5
- package/utils/converters/Converter.js.map +1 -1
- package/utils/converters/ConverterCollection.js +13 -7
- package/utils/converters/ConverterCollection.js.map +1 -1
- package/utils/converters/valueKeyStorageConverter.d.ts +1 -5
- package/utils/converters/valueKeyStorageConverter.js +34 -21
- package/utils/converters/valueKeyStorageConverter.js.map +1 -1
- package/utils/createTypeFromFields.d.ts +1 -0
- package/utils/createTypeFromFields.js +14 -7
- package/utils/createTypeFromFields.js.map +1 -1
- package/utils/createTypeName.d.ts +0 -2
- package/utils/createTypeName.js +3 -9
- package/utils/createTypeName.js.map +1 -1
- package/utils/date.d.ts +10 -0
- package/utils/date.js +36 -0
- package/utils/date.js.map +1 -0
- package/utils/entryStorage.d.ts +4 -4
- package/utils/entryStorage.js +6 -4
- package/utils/entryStorage.js.map +1 -1
- package/utils/filterAsync.js +9 -8
- package/utils/filterAsync.js.map +1 -1
- package/utils/getBaseFieldType.d.ts +1 -3
- package/utils/getBaseFieldType.js +3 -1
- package/utils/getBaseFieldType.js.map +1 -1
- package/utils/getEntryDescription.d.ts +2 -0
- package/utils/getEntryDescription.js +19 -0
- package/utils/getEntryDescription.js.map +1 -0
- package/utils/getEntryImage.d.ts +2 -0
- package/utils/getEntryImage.js +19 -0
- package/utils/getEntryImage.js.map +1 -0
- package/utils/getEntryTitle.d.ts +1 -1
- package/utils/getEntryTitle.js +3 -1
- package/utils/getEntryTitle.js.map +1 -1
- package/utils/getSchemaFromFieldPlugins.d.ts +13 -2
- package/utils/getSchemaFromFieldPlugins.js +22 -4
- package/utils/getSchemaFromFieldPlugins.js.map +1 -1
- package/utils/identity.d.ts +2 -0
- package/utils/identity.js +20 -0
- package/utils/identity.js.map +1 -0
- package/utils/incrementEntryIdVersion.d.ts +5 -0
- package/utils/incrementEntryIdVersion.js +31 -0
- package/utils/incrementEntryIdVersion.js.map +1 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +18 -0
- package/utils/index.js.map +1 -0
- package/utils/permissions/EntriesPermissions.d.ts +4 -0
- package/utils/permissions/EntriesPermissions.js +11 -0
- package/utils/permissions/EntriesPermissions.js.map +1 -0
- package/utils/permissions/ModelGroupsPermissions.d.ts +9 -0
- package/utils/permissions/ModelGroupsPermissions.js +50 -0
- package/utils/permissions/ModelGroupsPermissions.js.map +1 -0
- package/utils/permissions/ModelsPermissions.d.ts +22 -0
- package/utils/permissions/ModelsPermissions.js +90 -0
- package/utils/permissions/ModelsPermissions.js.map +1 -0
- package/utils/renderFields.d.ts +4 -2
- package/utils/renderFields.js +13 -3
- package/utils/renderFields.js.map +1 -1
- package/utils/renderGetFilterFields.d.ts +2 -2
- package/utils/renderGetFilterFields.js +9 -21
- package/utils/renderGetFilterFields.js.map +1 -1
- package/utils/renderInputFields.d.ts +4 -2
- package/utils/renderInputFields.js +20 -6
- package/utils/renderInputFields.js.map +1 -1
- package/utils/renderListFilterFields.d.ts +3 -1
- package/utils/renderListFilterFields.js +25 -22
- package/utils/renderListFilterFields.js.map +1 -1
- package/utils/renderSortEnum.d.ts +3 -2
- package/utils/renderSortEnum.js +10 -3
- package/utils/renderSortEnum.js.map +1 -1
- package/utils/toSlug.js +3 -1
- package/utils/toSlug.js.map +1 -1
- package/validators/dateGte.js +3 -1
- package/validators/dateGte.js.map +1 -1
- package/validators/dateLte.js +3 -1
- package/validators/dateLte.js.map +1 -1
- package/validators/gte.js +4 -3
- package/validators/gte.js.map +1 -1
- package/validators/in.js +4 -3
- package/validators/in.js.map +1 -1
- package/validators/index.js +4 -3
- package/validators/index.js.map +1 -1
- package/validators/lte.js +4 -3
- package/validators/lte.js.map +1 -1
- package/validators/maxLength.js +4 -3
- package/validators/maxLength.js.map +1 -1
- package/validators/minLength.js +4 -3
- package/validators/minLength.js.map +1 -1
- package/validators/pattern.js +5 -3
- package/validators/pattern.js.map +1 -1
- package/validators/patternPlugins/email.js +3 -1
- package/validators/patternPlugins/email.js.map +1 -1
- package/validators/patternPlugins/index.js +3 -1
- package/validators/patternPlugins/index.js.map +1 -1
- package/validators/patternPlugins/lowerCase.js +3 -1
- package/validators/patternPlugins/lowerCase.js.map +1 -1
- package/validators/patternPlugins/lowerCaseSpace.js +3 -1
- package/validators/patternPlugins/lowerCaseSpace.js.map +1 -1
- package/validators/patternPlugins/upperCase.js +3 -1
- package/validators/patternPlugins/upperCase.js.map +1 -1
- package/validators/patternPlugins/upperCaseSpace.js +3 -1
- package/validators/patternPlugins/upperCaseSpace.js.map +1 -1
- package/validators/patternPlugins/url.js +3 -1
- package/validators/patternPlugins/url.js.map +1 -1
- package/validators/required.js +3 -1
- package/validators/required.js.map +1 -1
- package/validators/timeGte.js +4 -3
- package/validators/timeGte.js.map +1 -1
- package/validators/timeLte.js +4 -3
- package/validators/timeLte.js.map +1 -1
- package/validators/unique.js +4 -2
- package/validators/unique.js.map +1 -1
- package/crud/contentModel/afterCreate.d.ts +0 -8
- package/crud/contentModel/afterCreate.js +0 -16
- package/crud/contentModel/afterCreate.js.map +0 -1
- package/crud/contentModel/afterCreateFrom.d.ts +0 -8
- package/crud/contentModel/afterCreateFrom.js +0 -16
- package/crud/contentModel/afterCreateFrom.js.map +0 -1
- package/crud/contentModel/afterDelete.d.ts +0 -8
- package/crud/contentModel/afterDelete.js +0 -16
- package/crud/contentModel/afterDelete.js.map +0 -1
- package/crud/contentModel/afterUpdate.d.ts +0 -8
- package/crud/contentModel/afterUpdate.js +0 -16
- package/crud/contentModel/afterUpdate.js.map +0 -1
- package/crud/contentModel/createFieldModels.d.ts +0 -2
- package/crud/contentModel/createFieldModels.js +0 -26
- package/crud/contentModel/createFieldModels.js.map +0 -1
- package/crud/contentModel/fieldIdValidation.d.ts +0 -1
- package/crud/contentModel/fieldIdValidation.js +0 -25
- package/crud/contentModel/fieldIdValidation.js.map +0 -1
- package/crud/contentModel/idValidation.d.ts +0 -1
- package/crud/contentModel/idValidation.js +0 -22
- package/crud/contentModel/idValidation.js.map +0 -1
- package/crud/contentModel/models.d.ts +0 -4
- package/crud/contentModel/models.js +0 -192
- package/crud/contentModel/models.js.map +0 -1
- package/crud/contentModel/systemFields.d.ts +0 -1
- package/crud/contentModel/systemFields.js +0 -8
- package/crud/contentModel/systemFields.js.map +0 -1
- package/crud/contentModel/validateLayout.d.ts +0 -2
- package/crud/contentModel/validateLayout.js +0 -28
- package/crud/contentModel/validateLayout.js.map +0 -1
- package/crud/settings.crud.d.ts +0 -10
- package/crud/settings.crud.js +0 -71
- package/crud/settings.crud.js.map +0 -1
- package/graphql/schema/resolvers/commonFieldResolvers.d.ts +0 -6
- package/graphql/schema/resolvers/commonFieldResolvers.js +0 -12
- package/graphql/schema/resolvers/commonFieldResolvers.js.map +0 -1
- package/upgrades/5.33.0/index.d.ts +0 -3
- package/upgrades/5.33.0/index.js +0 -159
- package/upgrades/5.33.0/index.js.map +0 -1
- package/upgrades/index.d.ts +0 -1
- package/upgrades/index.js +0 -9
- package/upgrades/index.js.map +0 -1
- package/utils/ownership.d.ts +0 -8
- package/utils/ownership.js +0 -33
- package/utils/ownership.js.map +0 -1
- package/utils/permissions.d.ts +0 -7
- package/utils/permissions.js +0 -91
- package/utils/permissions.js.map +0 -1
- package/utils/pluralizedTypeName.d.ts +0 -1
- package/utils/pluralizedTypeName.js +0 -20
- package/utils/pluralizedTypeName.js.map +0 -1
- package/validators/dynamicZone.d.ts +0 -2
- package/validators/dynamicZone.js +0 -20
- package/validators/dynamicZone.js.map +0 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.listModelsFromDatabase = void 0;
|
|
7
|
+
var _modelApiName = require("./compatibility/modelApiName");
|
|
8
|
+
var _ensureTypeTag = require("./ensureTypeTag");
|
|
9
|
+
const listModelsFromDatabase = async params => {
|
|
10
|
+
const {
|
|
11
|
+
storageOperations,
|
|
12
|
+
getTenant,
|
|
13
|
+
getLocale
|
|
14
|
+
} = params;
|
|
15
|
+
const models = await storageOperations.models.list({
|
|
16
|
+
where: {
|
|
17
|
+
tenant: getTenant().id,
|
|
18
|
+
locale: getLocale().code
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return models.map(model => {
|
|
22
|
+
return {
|
|
23
|
+
...model,
|
|
24
|
+
tags: (0, _ensureTypeTag.ensureTypeTag)(model),
|
|
25
|
+
tenant: model.tenant || getTenant().id,
|
|
26
|
+
locale: model.locale || getLocale().code,
|
|
27
|
+
/**
|
|
28
|
+
* TODO: remove in v5.36.0
|
|
29
|
+
* This is for backward compatibility while migrations are not yet executed.
|
|
30
|
+
*/
|
|
31
|
+
singularApiName: (0, _modelApiName.ensureSingularApiName)(model),
|
|
32
|
+
pluralApiName: (0, _modelApiName.ensurePluralApiName)(model)
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
exports.listModelsFromDatabase = listModelsFromDatabase;
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=listModelsFromDatabase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_modelApiName","require","_ensureTypeTag","listModelsFromDatabase","params","storageOperations","getTenant","getLocale","models","list","where","tenant","id","locale","code","map","model","tags","ensureTypeTag","singularApiName","ensureSingularApiName","pluralApiName","ensurePluralApiName","exports"],"sources":["listModelsFromDatabase.ts"],"sourcesContent":["import { CmsModel, HeadlessCmsStorageOperations } from \"~/types\";\nimport {\n ensurePluralApiName,\n ensureSingularApiName\n} from \"~/crud/contentModel/compatibility/modelApiName\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { I18NLocale } from \"@webiny/api-i18n/types\";\nimport { ensureTypeTag } from \"./ensureTypeTag\";\n\ninterface Params {\n storageOperations: HeadlessCmsStorageOperations;\n getTenant: () => Tenant;\n getLocale: () => I18NLocale;\n}\n\nexport const listModelsFromDatabase = async (params: Params): Promise<CmsModel[]> => {\n const { storageOperations, getTenant, getLocale } = params;\n const models = await storageOperations.models.list({\n where: {\n tenant: getTenant().id,\n locale: getLocale().code\n }\n });\n return models.map(model => {\n return {\n ...model,\n tags: ensureTypeTag(model),\n tenant: model.tenant || getTenant().id,\n locale: model.locale || getLocale().code,\n /**\n * TODO: remove in v5.36.0\n * This is for backward compatibility while migrations are not yet executed.\n */\n singularApiName: ensureSingularApiName(model),\n pluralApiName: ensurePluralApiName(model)\n };\n });\n};\n"],"mappings":";;;;;;AACA,IAAAA,aAAA,GAAAC,OAAA;AAMA,IAAAC,cAAA,GAAAD,OAAA;AAQO,MAAME,sBAAsB,GAAG,MAAOC,MAAc,IAA0B;EACjF,MAAM;IAAEC,iBAAiB;IAAEC,SAAS;IAAEC;EAAU,CAAC,GAAGH,MAAM;EAC1D,MAAMI,MAAM,GAAG,MAAMH,iBAAiB,CAACG,MAAM,CAACC,IAAI,CAAC;IAC/CC,KAAK,EAAE;MACHC,MAAM,EAAEL,SAAS,CAAC,CAAC,CAACM,EAAE;MACtBC,MAAM,EAAEN,SAAS,CAAC,CAAC,CAACO;IACxB;EACJ,CAAC,CAAC;EACF,OAAON,MAAM,CAACO,GAAG,CAACC,KAAK,IAAI;IACvB,OAAO;MACH,GAAGA,KAAK;MACRC,IAAI,EAAE,IAAAC,4BAAa,EAACF,KAAK,CAAC;MAC1BL,MAAM,EAAEK,KAAK,CAACL,MAAM,IAAIL,SAAS,CAAC,CAAC,CAACM,EAAE;MACtCC,MAAM,EAAEG,KAAK,CAACH,MAAM,IAAIN,SAAS,CAAC,CAAC,CAACO,IAAI;MACxC;AACZ;AACA;AACA;MACYK,eAAe,EAAE,IAAAC,mCAAqB,EAACJ,KAAK,CAAC;MAC7CK,aAAa,EAAE,IAAAC,iCAAmB,EAACN,KAAK;IAC5C,CAAC;EACL,CAAC,CAAC;AACN,CAAC;AAACO,OAAA,CAAApB,sBAAA,GAAAA,sBAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.validateEndingAllowed = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
var _isModelEndingAllowed = require("./isModelEndingAllowed");
|
|
10
|
+
const validateEndingAllowed = params => {
|
|
11
|
+
const {
|
|
12
|
+
model
|
|
13
|
+
} = params;
|
|
14
|
+
if ((0, _isModelEndingAllowed.isModelEndingAllowed)(model.singularApiName) === false) {
|
|
15
|
+
throw new _error.default(`Content model with singularApiName "${model.singularApiName}" is not allowed, as it ends in disallowed value.`, "MODEL_SINGULAR_API_NAME_ENDING_NOT_ALLOWED", {
|
|
16
|
+
input: model.singularApiName,
|
|
17
|
+
disallowedEnding: _isModelEndingAllowed.disallowedEnding
|
|
18
|
+
});
|
|
19
|
+
} else if ((0, _isModelEndingAllowed.isModelEndingAllowed)(model.pluralApiName) === false) {
|
|
20
|
+
throw new _error.default(`Content model with pluralApiName "${model.pluralApiName}" is not allowed, as it ends in disallowed value.`, "MODEL_PLURAL_API_NAME_NOT_ENDING_ALLOWED", {
|
|
21
|
+
input: model.pluralApiName,
|
|
22
|
+
disallowedEnding: _isModelEndingAllowed.disallowedEnding
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
exports.validateEndingAllowed = validateEndingAllowed;
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=endingAllowed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_isModelEndingAllowed","validateEndingAllowed","params","model","isModelEndingAllowed","singularApiName","WebinyError","input","disallowedEnding","pluralApiName","exports"],"sources":["endingAllowed.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { disallowedEnding, isModelEndingAllowed } from \"./isModelEndingAllowed\";\nimport { CmsModel } from \"~/types\";\n\ninterface Params {\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validateEndingAllowed = (params: Params): void => {\n const { model } = params;\n if (isModelEndingAllowed(model.singularApiName) === false) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.singularApiName}\" is not allowed, as it ends in disallowed value.`,\n \"MODEL_SINGULAR_API_NAME_ENDING_NOT_ALLOWED\",\n {\n input: model.singularApiName,\n disallowedEnding\n }\n );\n } else if (isModelEndingAllowed(model.pluralApiName) === false) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.pluralApiName}\" is not allowed, as it ends in disallowed value.`,\n \"MODEL_PLURAL_API_NAME_NOT_ENDING_ALLOWED\",\n {\n input: model.pluralApiName,\n disallowedEnding: disallowedEnding\n }\n );\n }\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,qBAAA,GAAAD,OAAA;AAOO,MAAME,qBAAqB,GAAIC,MAAc,IAAW;EAC3D,MAAM;IAAEC;EAAM,CAAC,GAAGD,MAAM;EACxB,IAAI,IAAAE,0CAAoB,EAACD,KAAK,CAACE,eAAe,CAAC,KAAK,KAAK,EAAE;IACvD,MAAM,IAAIC,cAAW,CAChB,uCAAsCH,KAAK,CAACE,eAAgB,mDAAkD,EAC/G,4CAA4C,EAC5C;MACIE,KAAK,EAAEJ,KAAK,CAACE,eAAe;MAC5BG,gBAAgB,EAAhBA;IACJ,CACJ,CAAC;EACL,CAAC,MAAM,IAAI,IAAAJ,0CAAoB,EAACD,KAAK,CAACM,aAAa,CAAC,KAAK,KAAK,EAAE;IAC5D,MAAM,IAAIH,cAAW,CAChB,qCAAoCH,KAAK,CAACM,aAAc,mDAAkD,EAC3G,0CAA0C,EAC1C;MACIF,KAAK,EAAEJ,KAAK,CAACM,aAAa;MAC1BD,gBAAgB,EAAEA;IACtB,CACJ,CAAC;EACL;AACJ,CAAC;AAACE,OAAA,CAAAT,qBAAA,GAAAA,qBAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isModelEndingAllowed = exports.disallowedEnding = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* This list is to disallow creating models that might interfere with GraphQL schema creation.
|
|
9
|
+
* Add more if required.
|
|
10
|
+
*/
|
|
11
|
+
const disallowedEnding = ["Response", "List", "Meta", "Input", "Sorter", "RefType"];
|
|
12
|
+
exports.disallowedEnding = disallowedEnding;
|
|
13
|
+
const isModelEndingAllowed = apiName => {
|
|
14
|
+
for (const ending of disallowedEnding) {
|
|
15
|
+
const re = new RegExp(`${ending}$`);
|
|
16
|
+
const matched = apiName.match(re);
|
|
17
|
+
if (matched === null) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
};
|
|
24
|
+
exports.isModelEndingAllowed = isModelEndingAllowed;
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=isModelEndingAllowed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["disallowedEnding","exports","isModelEndingAllowed","apiName","ending","re","RegExp","matched","match"],"sources":["isModelEndingAllowed.ts"],"sourcesContent":["/**\n * This list is to disallow creating models that might interfere with GraphQL schema creation.\n * Add more if required.\n */\nexport const disallowedEnding: string[] = [\n \"Response\",\n \"List\",\n \"Meta\",\n \"Input\",\n \"Sorter\",\n \"RefType\"\n];\n\nexport const isModelEndingAllowed = (apiName: string): boolean => {\n for (const ending of disallowedEnding) {\n const re = new RegExp(`${ending}$`);\n const matched = apiName.match(re);\n if (matched === null) {\n continue;\n }\n return false;\n }\n return true;\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACO,MAAMA,gBAA0B,GAAG,CACtC,UAAU,EACV,MAAM,EACN,MAAM,EACN,OAAO,EACP,QAAQ,EACR,SAAS,CACZ;AAACC,OAAA,CAAAD,gBAAA,GAAAA,gBAAA;AAEK,MAAME,oBAAoB,GAAIC,OAAe,IAAc;EAC9D,KAAK,MAAMC,MAAM,IAAIJ,gBAAgB,EAAE;IACnC,MAAMK,EAAE,GAAG,IAAIC,MAAM,CAAE,GAAEF,MAAO,GAAE,CAAC;IACnC,MAAMG,OAAO,GAAGJ,OAAO,CAACK,KAAK,CAACH,EAAE,CAAC;IACjC,IAAIE,OAAO,KAAK,IAAI,EAAE;MAClB;IACJ;IACA,OAAO,KAAK;EAChB;EACA,OAAO,IAAI;AACf,CAAC;AAACN,OAAA,CAAAC,oBAAA,GAAAA,oBAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CmsModel } from "../../../types";
|
|
2
|
+
interface ModelIdAllowedParams {
|
|
3
|
+
model: Pick<CmsModel, "modelId">;
|
|
4
|
+
}
|
|
5
|
+
export declare const validateModelIdAllowed: (params: ModelIdAllowedParams) => void;
|
|
6
|
+
interface Params {
|
|
7
|
+
existingModel: Pick<CmsModel, "modelId">;
|
|
8
|
+
model: Pick<CmsModel, "modelId">;
|
|
9
|
+
}
|
|
10
|
+
export declare const validateExistingModelId: (params: Params) => void;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.validateModelIdAllowed = exports.validateExistingModelId = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
const disallowedModelIdList = ["contentModel", "contentModels", "contentModelGroup", "contentModelGroups"];
|
|
10
|
+
const isModelIdAllowed = modelId => {
|
|
11
|
+
return disallowedModelIdList.includes(modelId) === false;
|
|
12
|
+
};
|
|
13
|
+
const validateModelIdAllowed = params => {
|
|
14
|
+
const {
|
|
15
|
+
model
|
|
16
|
+
} = params;
|
|
17
|
+
if (isModelIdAllowed(model.modelId)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
throw new _error.default(`Provided model ID "${model.modelId}" is not allowed.`, "MODEL_ID_NOT_ALLOWED", {
|
|
21
|
+
input: model.modelId
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
exports.validateModelIdAllowed = validateModelIdAllowed;
|
|
25
|
+
const validateExistingModelId = params => {
|
|
26
|
+
const {
|
|
27
|
+
existingModel,
|
|
28
|
+
model
|
|
29
|
+
} = params;
|
|
30
|
+
if (existingModel.modelId === model.modelId) {
|
|
31
|
+
throw new _error.default(`Content model with modelId "${model.modelId}" already exists.`, "MODEL_ID_EXISTS", {
|
|
32
|
+
input: existingModel.modelId
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
exports.validateExistingModelId = validateExistingModelId;
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=modelId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","disallowedModelIdList","isModelIdAllowed","modelId","includes","validateModelIdAllowed","params","model","WebinyError","input","exports","validateExistingModelId","existingModel"],"sources":["modelId.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsModel } from \"~/types\";\n\nconst disallowedModelIdList: string[] = [\n \"contentModel\",\n \"contentModels\",\n \"contentModelGroup\",\n \"contentModelGroups\"\n];\nconst isModelIdAllowed = (modelId: string): boolean => {\n return disallowedModelIdList.includes(modelId) === false;\n};\n\ninterface ModelIdAllowedParams {\n model: Pick<CmsModel, \"modelId\">;\n}\n\nexport const validateModelIdAllowed = (params: ModelIdAllowedParams) => {\n const { model } = params;\n if (isModelIdAllowed(model.modelId)) {\n return;\n }\n throw new WebinyError(\n `Provided model ID \"${model.modelId}\" is not allowed.`,\n \"MODEL_ID_NOT_ALLOWED\",\n {\n input: model.modelId\n }\n );\n};\n\ninterface Params {\n existingModel: Pick<CmsModel, \"modelId\">;\n model: Pick<CmsModel, \"modelId\">;\n}\n\nexport const validateExistingModelId = (params: Params): void => {\n const { existingModel, model } = params;\n\n if (existingModel.modelId === model.modelId) {\n throw new WebinyError(\n `Content model with modelId \"${model.modelId}\" already exists.`,\n \"MODEL_ID_EXISTS\",\n {\n input: existingModel.modelId\n }\n );\n }\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,MAAMC,qBAA+B,GAAG,CACpC,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,oBAAoB,CACvB;AACD,MAAMC,gBAAgB,GAAIC,OAAe,IAAc;EACnD,OAAOF,qBAAqB,CAACG,QAAQ,CAACD,OAAO,CAAC,KAAK,KAAK;AAC5D,CAAC;AAMM,MAAME,sBAAsB,GAAIC,MAA4B,IAAK;EACpE,MAAM;IAAEC;EAAM,CAAC,GAAGD,MAAM;EACxB,IAAIJ,gBAAgB,CAACK,KAAK,CAACJ,OAAO,CAAC,EAAE;IACjC;EACJ;EACA,MAAM,IAAIK,cAAW,CAChB,sBAAqBD,KAAK,CAACJ,OAAQ,mBAAkB,EACtD,sBAAsB,EACtB;IACIM,KAAK,EAAEF,KAAK,CAACJ;EACjB,CACJ,CAAC;AACL,CAAC;AAACO,OAAA,CAAAL,sBAAA,GAAAA,sBAAA;AAOK,MAAMM,uBAAuB,GAAIL,MAAc,IAAW;EAC7D,MAAM;IAAEM,aAAa;IAAEL;EAAM,CAAC,GAAGD,MAAM;EAEvC,IAAIM,aAAa,CAACT,OAAO,KAAKI,KAAK,CAACJ,OAAO,EAAE;IACzC,MAAM,IAAIK,cAAW,CAChB,+BAA8BD,KAAK,CAACJ,OAAQ,mBAAkB,EAC/D,iBAAiB,EACjB;MACIM,KAAK,EAAEG,aAAa,CAACT;IACzB,CACJ,CAAC;EACL;AACJ,CAAC;AAACO,OAAA,CAAAC,uBAAA,GAAAA,uBAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CmsModel } from "../../../types";
|
|
2
|
+
interface Params {
|
|
3
|
+
existingModel: Pick<CmsModel, "singularApiName" | "pluralApiName">;
|
|
4
|
+
model: Pick<CmsModel, "singularApiName" | "pluralApiName">;
|
|
5
|
+
}
|
|
6
|
+
export declare const validatePluralApiName: (params: Params) => void;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.validatePluralApiName = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
const validatePluralApiName = params => {
|
|
10
|
+
const {
|
|
11
|
+
existingModel,
|
|
12
|
+
model
|
|
13
|
+
} = params;
|
|
14
|
+
if (existingModel.singularApiName === model.pluralApiName) {
|
|
15
|
+
throw new _error.default(`Content model with singularApiName "${model.pluralApiName}" already exists.`, "MODEL_SINGULAR_API_NAME_EXISTS", {
|
|
16
|
+
input: model.pluralApiName
|
|
17
|
+
});
|
|
18
|
+
} else if (existingModel.pluralApiName === model.pluralApiName) {
|
|
19
|
+
throw new _error.default(`Content model with pluralApiName "${model.pluralApiName}" already exists.`, "MODEL_PLURAL_API_NAME_EXISTS", {
|
|
20
|
+
input: model.pluralApiName
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
exports.validatePluralApiName = validatePluralApiName;
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=pluralApiName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","validatePluralApiName","params","existingModel","model","singularApiName","pluralApiName","WebinyError","input","exports"],"sources":["pluralApiName.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsModel } from \"~/types\";\n\ninterface Params {\n existingModel: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validatePluralApiName = (params: Params): void => {\n const { existingModel, model } = params;\n\n if (existingModel.singularApiName === model.pluralApiName) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.pluralApiName}\" already exists.`,\n \"MODEL_SINGULAR_API_NAME_EXISTS\",\n {\n input: model.pluralApiName\n }\n );\n } else if (existingModel.pluralApiName === model.pluralApiName) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.pluralApiName}\" already exists.`,\n \"MODEL_PLURAL_API_NAME_EXISTS\",\n {\n input: model.pluralApiName\n }\n );\n }\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAQO,MAAMC,qBAAqB,GAAIC,MAAc,IAAW;EAC3D,MAAM;IAAEC,aAAa;IAAEC;EAAM,CAAC,GAAGF,MAAM;EAEvC,IAAIC,aAAa,CAACE,eAAe,KAAKD,KAAK,CAACE,aAAa,EAAE;IACvD,MAAM,IAAIC,cAAW,CAChB,uCAAsCH,KAAK,CAACE,aAAc,mBAAkB,EAC7E,gCAAgC,EAChC;MACIE,KAAK,EAAEJ,KAAK,CAACE;IACjB,CACJ,CAAC;EACL,CAAC,MAAM,IAAIH,aAAa,CAACG,aAAa,KAAKF,KAAK,CAACE,aAAa,EAAE;IAC5D,MAAM,IAAIC,cAAW,CAChB,qCAAoCH,KAAK,CAACE,aAAc,mBAAkB,EAC3E,8BAA8B,EAC9B;MACIE,KAAK,EAAEJ,KAAK,CAACE;IACjB,CACJ,CAAC;EACL;AACJ,CAAC;AAACG,OAAA,CAAAR,qBAAA,GAAAA,qBAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CmsModel } from "../../../types";
|
|
2
|
+
interface Params {
|
|
3
|
+
existingModel: Pick<CmsModel, "singularApiName" | "pluralApiName">;
|
|
4
|
+
model: Pick<CmsModel, "singularApiName" | "pluralApiName">;
|
|
5
|
+
}
|
|
6
|
+
export declare const validateSingularApiName: (params: Params) => void;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.validateSingularApiName = void 0;
|
|
8
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
+
const validateSingularApiName = params => {
|
|
10
|
+
const {
|
|
11
|
+
existingModel,
|
|
12
|
+
model
|
|
13
|
+
} = params;
|
|
14
|
+
if (existingModel.singularApiName === model.singularApiName) {
|
|
15
|
+
throw new _error.default(`Content model with singularApiName "${model.singularApiName}" already exists.`, "MODEL_SINGULAR_API_NAME_EXISTS", {
|
|
16
|
+
input: model.singularApiName
|
|
17
|
+
});
|
|
18
|
+
} else if (existingModel.pluralApiName === model.singularApiName) {
|
|
19
|
+
throw new _error.default(`Content model with pluralApiName "${model.singularApiName}" already exists.`, "MODEL_PLURAL_API_NAME_EXISTS", {
|
|
20
|
+
input: model.singularApiName
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
exports.validateSingularApiName = validateSingularApiName;
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=singularApiName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","validateSingularApiName","params","existingModel","model","singularApiName","WebinyError","input","pluralApiName","exports"],"sources":["singularApiName.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsModel } from \"~/types\";\n\ninterface Params {\n existingModel: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validateSingularApiName = (params: Params): void => {\n const { existingModel, model } = params;\n\n if (existingModel.singularApiName === model.singularApiName) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.singularApiName}\" already exists.`,\n \"MODEL_SINGULAR_API_NAME_EXISTS\",\n {\n input: model.singularApiName\n }\n );\n } else if (existingModel.pluralApiName === model.singularApiName) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.singularApiName}\" already exists.`,\n \"MODEL_PLURAL_API_NAME_EXISTS\",\n {\n input: model.singularApiName\n }\n );\n }\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAQO,MAAMC,uBAAuB,GAAIC,MAAc,IAAW;EAC7D,MAAM;IAAEC,aAAa;IAAEC;EAAM,CAAC,GAAGF,MAAM;EAEvC,IAAIC,aAAa,CAACE,eAAe,KAAKD,KAAK,CAACC,eAAe,EAAE;IACzD,MAAM,IAAIC,cAAW,CAChB,uCAAsCF,KAAK,CAACC,eAAgB,mBAAkB,EAC/E,gCAAgC,EAChC;MACIE,KAAK,EAAEH,KAAK,CAACC;IACjB,CACJ,CAAC;EACL,CAAC,MAAM,IAAIF,aAAa,CAACK,aAAa,KAAKJ,KAAK,CAACC,eAAe,EAAE;IAC9D,MAAM,IAAIC,cAAW,CAChB,qCAAoCF,KAAK,CAACC,eAAgB,mBAAkB,EAC7E,8BAA8B,EAC9B;MACIE,KAAK,EAAEH,KAAK,CAACC;IACjB,CACJ,CAAC;EACL;AACJ,CAAC;AAACI,OAAA,CAAAR,uBAAA,GAAAA,uBAAA"}
|
|
@@ -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 \"
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_CmsModelPlugin","_validateModelFields","validateModel","params","model","context","plugins","modelPlugin","byType","CmsModelPlugin","type","find","item","contentModel","modelId","WebinyError","validateModelFields","exports"],"sources":["validateModel.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsModelPlugin } from \"~/plugins/CmsModelPlugin\";\nimport { CmsContext, CmsModel } from \"~/types\";\nimport { validateModelFields } from \"./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,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AAEA,IAAAE,oBAAA,GAAAF,OAAA;AASO,MAAMG,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,CACJ,CAAC;EACL;EAEA,MAAM,IAAAE,wCAAmB,EAACb,MAAM,CAAC;AACrC,CAAC;AAACc,OAAA,CAAAf,aAAA,GAAAA,aAAA"}
|
|
@@ -5,68 +5,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.validateModelFields = void 0;
|
|
8
|
-
var
|
|
8
|
+
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
|
9
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
10
10
|
var _createManageSDL = require("../../graphql/schema/createManageSDL");
|
|
11
|
-
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
|
12
11
|
var _createFieldStorageId = require("./createFieldStorageId");
|
|
13
12
|
var _getBaseFieldType = require("../../utils/getBaseFieldType");
|
|
13
|
+
var _titleField = require("./fields/titleField");
|
|
14
|
+
var _descriptionField = require("./fields/descriptionField");
|
|
15
|
+
var _imageField = require("./fields/imageField");
|
|
14
16
|
var _plugins = require("../../plugins");
|
|
15
17
|
var _buildSchemaPlugins = require("../../graphql/buildSchemaPlugins");
|
|
16
18
|
var _createExecutableSchema = require("../../graphql/createExecutableSchema");
|
|
17
|
-
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
18
19
|
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
20
|
const extractInvalidField = (model, err) => {
|
|
68
|
-
|
|
69
|
-
const sdl = ((_err$source = err.source) === null || _err$source === void 0 ? void 0 : _err$source.body) || "";
|
|
21
|
+
const sdl = err.source?.body || "";
|
|
70
22
|
|
|
71
23
|
/**
|
|
72
24
|
* Find the invalid type
|
|
@@ -233,15 +185,17 @@ const createGraphQLSchema = async params => {
|
|
|
233
185
|
context,
|
|
234
186
|
model
|
|
235
187
|
} = params;
|
|
236
|
-
context.security.
|
|
237
|
-
|
|
238
|
-
|
|
188
|
+
const models = await context.security.withoutAuthorization(async () => {
|
|
189
|
+
return (await context.cms.listModels()).filter(model => {
|
|
190
|
+
return model.isPrivate !== true;
|
|
191
|
+
});
|
|
192
|
+
});
|
|
239
193
|
const modelPlugins = await (0, _buildSchemaPlugins.buildSchemaPlugins)({
|
|
240
194
|
context,
|
|
241
195
|
models: models.concat([model])
|
|
242
196
|
});
|
|
243
|
-
const plugins = context.plugins.byType(
|
|
244
|
-
const name = plugin.name || `${
|
|
197
|
+
const plugins = context.plugins.byType(_plugins.CmsGraphQLSchemaPlugin.type).reduce((collection, plugin) => {
|
|
198
|
+
const name = plugin.name || `${_plugins.CmsGraphQLSchemaPlugin.type}-${(0, _utils.generateAlphaNumericId)(16)}`;
|
|
245
199
|
collection[name] = plugin;
|
|
246
200
|
return collection;
|
|
247
201
|
}, {});
|
|
@@ -264,12 +218,15 @@ const extractErrorObject = error => {
|
|
|
264
218
|
};
|
|
265
219
|
const validateModelFields = async params => {
|
|
266
220
|
const {
|
|
221
|
+
models,
|
|
267
222
|
model,
|
|
268
223
|
original,
|
|
269
224
|
context
|
|
270
225
|
} = params;
|
|
271
226
|
const {
|
|
272
|
-
titleFieldId
|
|
227
|
+
titleFieldId,
|
|
228
|
+
descriptionFieldId,
|
|
229
|
+
imageFieldId
|
|
273
230
|
} = model;
|
|
274
231
|
const {
|
|
275
232
|
plugins
|
|
@@ -290,7 +247,7 @@ const validateModelFields = async params => {
|
|
|
290
247
|
const fieldTypePlugins = plugins.byType("cms-model-field-to-graphql");
|
|
291
248
|
validateFields({
|
|
292
249
|
fields,
|
|
293
|
-
originalFields:
|
|
250
|
+
originalFields: original?.fields || [],
|
|
294
251
|
lockedFields,
|
|
295
252
|
plugins: fieldTypePlugins
|
|
296
253
|
});
|
|
@@ -300,8 +257,10 @@ const validateModelFields = async params => {
|
|
|
300
257
|
* Make sure that this model can be safely converted to a GraphQL SDL
|
|
301
258
|
*/
|
|
302
259
|
const schema = (0, _createManageSDL.createManageSDL)({
|
|
260
|
+
models,
|
|
303
261
|
model,
|
|
304
|
-
fieldTypePlugins: fieldTypePlugins.reduce((acc, pl) => (
|
|
262
|
+
fieldTypePlugins: fieldTypePlugins.reduce((acc, pl) => ({
|
|
263
|
+
...acc,
|
|
305
264
|
[pl.fieldType]: pl
|
|
306
265
|
}), {}),
|
|
307
266
|
sorterPlugins
|
|
@@ -330,7 +289,9 @@ const validateModelFields = async params => {
|
|
|
330
289
|
});
|
|
331
290
|
}
|
|
332
291
|
}
|
|
333
|
-
model.titleFieldId = getContentModelTitleFieldId(fields, titleFieldId);
|
|
292
|
+
model.titleFieldId = (0, _titleField.getContentModelTitleFieldId)(fields, titleFieldId);
|
|
293
|
+
model.descriptionFieldId = (0, _descriptionField.getContentModelDescriptionFieldId)(fields, descriptionFieldId);
|
|
294
|
+
model.imageFieldId = (0, _imageField.getContentModelImageFieldId)(fields, imageFieldId);
|
|
334
295
|
const cmsLockedFieldPlugins = plugins.byType("cms-model-locked-field");
|
|
335
296
|
|
|
336
297
|
/**
|
|
@@ -347,7 +308,7 @@ const validateModelFields = async params => {
|
|
|
347
308
|
if (!existingField) {
|
|
348
309
|
continue;
|
|
349
310
|
}
|
|
350
|
-
if (lockedField.multipleValues !== existingField.multipleValues) {
|
|
311
|
+
if (Boolean(lockedField.multipleValues) !== Boolean(existingField.multipleValues)) {
|
|
351
312
|
throw new _error.default(`Cannot change "multipleValues" for the "${lockedField.fieldId}" field because it's already in use in created content.`, "ENTRY_FIELD_USED", {
|
|
352
313
|
reason: `"multipleValues" changed`,
|
|
353
314
|
field: existingField
|
|
@@ -377,4 +338,6 @@ const validateModelFields = async params => {
|
|
|
377
338
|
}
|
|
378
339
|
}
|
|
379
340
|
};
|
|
380
|
-
exports.validateModelFields = validateModelFields;
|
|
341
|
+
exports.validateModelFields = validateModelFields;
|
|
342
|
+
|
|
343
|
+
//# sourceMappingURL=validateModelFields.js.map
|
|
@@ -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","idList","fieldIdList","storageIdList","baseType","plugin","fieldType","Error","id","push","originalField","isLocked","some","lockedField","createFieldStorageId","label","validateChildFields","validate","createGraphQLSchema","context","security","disableAuthorization","models","cms","listModels","enableAuthorization","modelPlugins","buildSchemaPlugins","concat","byType","GraphQLSchemaPlugin","reduce","collection","name","generateAlphaNumericId","createExecutableSchema","Object","values","extractErrorObject","error","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\";\nimport { generateAlphaNumericId } from \"@webiny/utils\";\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 context.security.disableAuthorization();\n const models = await context.cms.listModels();\n context.security.enableAuthorization();\n\n const modelPlugins = await buildSchemaPlugins({\n context,\n models: models.concat([model])\n });\n\n const plugins = context.plugins\n .byType<GraphQLSchemaPlugin<CmsContext>>(GraphQLSchemaPlugin.type)\n .reduce<Record<string, GraphQLSchemaPlugin<CmsContext>>>((collection, plugin) => {\n const name = plugin.name || `${plugin.type}-${generateAlphaNumericId(16)}`;\n collection[name] = plugin;\n return collection;\n }, {});\n for (const plugin of modelPlugins) {\n const name = plugin.name || `${plugin.type}-${generateAlphaNumericId(16)}`;\n plugins[name] = plugin;\n }\n\n return createExecutableSchema({\n plugins: Object.values(plugins)\n });\n};\n\nconst extractErrorObject = (error: any) => {\n return [\"message\", \"code\", \"data\", \"stack\"].reduce<Record<string, any>>((output, key) => {\n if (!error[key]) {\n return output;\n }\n output[key] = error[key];\n return output;\n }, {});\n};\n\ninterface ValidateModelFieldsParams {\n 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 }\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;AACA;AAEA,MAAMA,mBAAmB,GAAG,IAAI;AAEhC,MAAMC,sBAAsB,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC;AAEjD,MAAMC,2BAA2B,GAAG,CAACC,MAAuB,EAAEC,YAAqB,KAAa;EAC5F;AACJ;AACA;EACI,IAAID,MAAM,CAACE,MAAM,KAAK,CAAC,EAAE;IACrB,OAAOL,mBAAmB;EAC9B;EACA;AACJ;AACA;AACA;AACA;EACI,IAAI,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D,aAAa,GAAGpG,MAAM,CAACI,IAAI,CAACiG,IAAI,IAAIA,IAAI,CAACtF,SAAS,KAAK6C,WAAW,CAACpD,OAAO,CAAC;;IAEjF;AACR;AACA;AACA;IACQ,IAAI,CAAC4F,aAAa,EAAE;MAChB;IACJ;IAEA,IAAIxC,WAAW,CAACrD,cAAc,KAAK6F,aAAa,CAAC7F,cAAc,EAAE;MAC7D,MAAM,IAAII,cAAW,CAChB,2CAA0CiD,WAAW,CAACpD,OAAQ,yDAAwD,EACvH,kBAAkB,EAClB;QACI8F,MAAM,EAAG,0BAAyB;QAClCjG,KAAK,EAAE+F;MACX,CAAC,CACJ;IACL;IAEA,MAAM/C,SAAS,GAAG,IAAA/C,kCAAgB,EAAC8F,aAAa,CAAC;IACjD,IAAIxC,WAAW,CAAC/C,IAAI,KAAKwC,SAAS,EAAE;MAChC,MAAM,IAAI1C,cAAW,CAChB,qCAAoCiD,WAAW,CAACpD,OAAQ,yDAAwD,EACjH,kBAAkB,EAClB;QACI8F,MAAM,EAAG,gBAAe;QACxBC,eAAe,EAAE3C,WAAW,CAAC/C,IAAI;QACjC2F,iBAAiB,EAAEnD;MACvB,CAAC,CACJ;IACL;;IAEA;AACR;AACA;IACQ,MAAMoD,kBAAkB,GAAGN,qBAAqB,CAACO,MAAM,CACnDT,EAAE,IAAIA,EAAE,CAAC5C,SAAS,KAAK,IAAA/C,kCAAgB,EAACsD,WAAW,CAAC,CACvD;IACD,KAAK,MAAMR,MAAM,IAAIqD,kBAAkB,EAAE;MACrC,IAAI,OAAOrD,MAAM,CAACuD,gBAAgB,KAAK,UAAU,EAAE;QAC/C;MACJ;MACAvD,MAAM,CAACuD,gBAAgB,CAAC;QACpB/C,WAAW;QACXvD,KAAK,EAAE+F;MACX,CAAC,CAAC;IACN;EACJ;AACJ,CAAC;AAAC"}
|
|
1
|
+
{"version":3,"names":["_graphqlTag","_interopRequireDefault","require","_error","_createManageSDL","_createFieldStorageId","_getBaseFieldType","_titleField","_descriptionField","_imageField","_plugins","_buildSchemaPlugins","_createExecutableSchema","_utils","extractInvalidField","model","err","sdl","source","body","line","lineNumber","locations","sdlLines","split","sdlLine","gqlType","i","includes","match","invalidField","undefined","Array","isArray","fieldRegex","RegExp","matched","message","data","modelId","code","join","createValidateChildFields","plugins","fields","originalFields","length","validateFields","lockedFields","params","idList","fieldIdList","storageIdList","field","baseType","getBaseFieldType","plugin","find","fieldType","Error","id","WebinyError","storageId","fieldId","push","originalField","f","isLocked","some","lockedField","createFieldStorageId","label","validateChildFields","validate","createGraphQLSchema","context","models","security","withoutAuthorization","cms","listModels","filter","isPrivate","modelPlugins","buildSchemaPlugins","concat","byType","CmsGraphQLSchemaPlugin","type","reduce","collection","name","generateAlphaNumericId","createExecutableSchema","Object","values","extractErrorObject","error","output","key","validateModelFields","original","titleFieldId","descriptionFieldId","imageFieldId","fieldTypePlugins","sorterPlugins","CmsGraphQLSchemaSorterPlugin","schema","createManageSDL","acc","pl","gql","getContentModelTitleFieldId","getContentModelDescriptionFieldId","getContentModelImageFieldId","cmsLockedFieldPlugins","existingField","item","Boolean","multipleValues","reason","lockedFieldType","existingFieldType","lockedFieldsByType","checkLockedField","exports"],"sources":["validateModelFields.ts"],"sourcesContent":["import gql from \"graphql-tag\";\nimport WebinyError from \"@webiny/error\";\nimport {\n CmsModel,\n CmsContext,\n CmsModelField,\n CmsModelFieldToGraphQLPlugin,\n CmsModelFieldToGraphQLPluginValidateChildFieldsValidate,\n CmsModelLockedFieldPlugin,\n LockedField\n} from \"~/types\";\nimport { createManageSDL } from \"~/graphql/schema/createManageSDL\";\nimport { createFieldStorageId } from \"./createFieldStorageId\";\nimport { GraphQLError } from \"graphql\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\nimport { getContentModelTitleFieldId } from \"./fields/titleField\";\nimport { getContentModelDescriptionFieldId } from \"./fields/descriptionField\";\nimport { getContentModelImageFieldId } from \"./fields/imageField\";\nimport { CmsGraphQLSchemaPlugin, CmsGraphQLSchemaSorterPlugin } from \"~/plugins\";\nimport { buildSchemaPlugins } from \"~/graphql/buildSchemaPlugins\";\nimport { createExecutableSchema } from \"~/graphql/createExecutableSchema\";\nimport { generateAlphaNumericId } from \"@webiny/utils\";\n\nconst extractInvalidField = (model: CmsModel, err: GraphQLError) => {\n const sdl = err.source?.body || \"\";\n\n /**\n * Find the invalid type\n */\n const { line: lineNumber } = err.locations\n ? err.locations[0]\n : {\n line: 0\n };\n const sdlLines = sdl.split(\"\\n\");\n let sdlLine;\n let gqlType;\n for (let i = lineNumber; i > 0; i--) {\n if (sdlLine && sdlLine.includes(\"type \")) {\n gqlType = sdlLine.match(/type\\s+(.*?)\\s+{/);\n break;\n }\n\n sdlLine = sdlLines[i];\n }\n\n let invalidField: string | undefined = undefined;\n if (Array.isArray(gqlType)) {\n const fieldRegex = new RegExp(`([^\\\\s+].*?):\\\\s+\\\\[?${gqlType[1]}!?\\\\]?`);\n\n const matched = sdl.match(fieldRegex);\n if (matched) {\n invalidField = matched[1];\n }\n }\n\n let message = `See more details in the browser console.`;\n if (invalidField) {\n message = `Please review the definition of \"${invalidField}\" field.`;\n }\n\n return {\n data: {\n modelId: model.modelId,\n sdl,\n invalidField\n },\n code: \"INVALID_MODEL_DEFINITION\",\n message: [`Model \"${model.modelId}\" was not saved!`, message].join(\"\\n\")\n };\n};\n\nconst createValidateChildFields = (\n plugins: CmsModelFieldToGraphQLPlugin[]\n): CmsModelFieldToGraphQLPluginValidateChildFieldsValidate => {\n return ({ fields, originalFields }) => {\n if (fields.length === 0 && originalFields.length === 0) {\n return;\n }\n validateFields({\n fields,\n originalFields,\n plugins,\n lockedFields: []\n });\n };\n};\n\ninterface ValidateFieldsParams {\n plugins: CmsModelFieldToGraphQLPlugin[];\n fields: CmsModelField[];\n originalFields: CmsModelField[];\n lockedFields: LockedField[];\n}\n\nconst validateFields = (params: ValidateFieldsParams) => {\n const { plugins, fields, originalFields, lockedFields } = params;\n\n const idList: string[] = [];\n const fieldIdList: string[] = [];\n const storageIdList: string[] = [];\n\n for (const field of fields) {\n const baseType = getBaseFieldType(field);\n const plugin = plugins.find(plugin => plugin.fieldType === baseType);\n\n if (!plugin) {\n throw new Error(\n `Cannot update content model because of the unknown \"${baseType}\" field.`\n );\n }\n /**\n * Check the field's id against existing ones.\n * There cannot be two fields with the same id.\n */\n if (idList.includes(field.id)) {\n throw new WebinyError(\n `Cannot update content model because field \"${\n field.storageId || field.fieldId\n }\" has id \"${field.id}\", which is already used.`\n );\n }\n idList.push(field.id);\n\n const originalField = originalFields.find(f => f.id === field.id);\n /**\n * Field MUST have an fieldId defined.\n */\n if (!field.fieldId) {\n throw new WebinyError(`Field does not have an \"fieldId\" defined.`, \"MISSING_FIELD_ID\", {\n field\n });\n }\n /**\n * If storageId does not match a certain pattern, add that pattern, but only if field is not locked (used) already.\n * This is to avoid errors in the already installed systems.\n *\n * Why are we using the @?\n *\n * It is not part of special characters for the query syntax in the Lucene.\n *\n * Relevant links:\n * https://lucene.apache.org/core/3_4_0/queryparsersyntax.html\n * https://discuss.elastic.co/t/special-characters-in-field-names/10658/3\n * https://discuss.elastic.co/t/illegal-characters-in-elasticsearch-field-names/17196/2\n */\n const isLocked = lockedFields.some(lockedField => {\n return lockedField.fieldId === field.storageId || lockedField.fieldId === field.fieldId;\n });\n if (!field.storageId) {\n /**\n * In case field is locked, we must set the storageId to the fieldId value.\n * This should not happen, because we upgrade all the fields in 5.33.0, but let's have a check just in case of some upgrade miss.\n */\n //\n if (isLocked) {\n field.storageId = field.fieldId;\n }\n /**\n * When having original field, just set the storageId to value from the originalField\n */\n //\n else if (originalField) {\n field.storageId = originalField.storageId;\n }\n /**\n * The last case is when no original field and not locked - so this is a completely new field.\n */\n //\n else {\n field.storageId = createFieldStorageId(field);\n }\n }\n /**\n * Check the field's fieldId against existing ones.\n * There cannot be two fields with the same fieldId - outside world identifier.\n */\n if (fieldIdList.includes(field.fieldId)) {\n throw new WebinyError(\n `Cannot update content model because field \"${field.storageId}\" has fieldId \"${field.fieldId}\", which is already used.`\n );\n }\n fieldIdList.push(field.fieldId);\n /**\n * Check the field's storageId against the existing ones.\n * There cannot be two fields with the same storageId.\n */\n if (storageIdList.includes(field.storageId)) {\n throw new WebinyError(\n `Cannot update content model because field \"${field.label}\" has storageId \"${field.storageId}\", which is already used.`\n );\n }\n storageIdList.push(field.storageId);\n /**\n * There might be some plugins which allow child fields.\n * We use this method to validate them as well.\n */\n if (!plugin.validateChildFields) {\n continue;\n }\n const validateChildFields = createValidateChildFields(plugins);\n plugin.validateChildFields({\n field,\n originalField,\n validate: validateChildFields\n });\n }\n};\n\ninterface CreateGraphQLSchemaParams {\n context: CmsContext;\n model: CmsModel;\n}\n\nconst createGraphQLSchema = async (params: CreateGraphQLSchemaParams): Promise<any> => {\n const { context, model } = params;\n\n const models = await context.security.withoutAuthorization(async () => {\n return (await context.cms.listModels()).filter((model): model is CmsModel => {\n return model.isPrivate !== true;\n });\n });\n\n const modelPlugins = await buildSchemaPlugins({\n context,\n models: models.concat([model])\n });\n\n const plugins = context.plugins\n .byType<CmsGraphQLSchemaPlugin>(CmsGraphQLSchemaPlugin.type)\n .reduce<Record<string, CmsGraphQLSchemaPlugin>>((collection, plugin) => {\n const name =\n plugin.name || `${CmsGraphQLSchemaPlugin.type}-${generateAlphaNumericId(16)}`;\n collection[name] = plugin;\n return collection;\n }, {});\n for (const plugin of modelPlugins) {\n const name = plugin.name || `${plugin.type}-${generateAlphaNumericId(16)}`;\n plugins[name] = plugin;\n }\n\n return createExecutableSchema({\n plugins: Object.values(plugins)\n });\n};\n\nconst extractErrorObject = (error: any) => {\n return [\"message\", \"code\", \"data\", \"stack\"].reduce<Record<string, any>>((output, key) => {\n if (!error[key]) {\n return output;\n }\n output[key] = error[key];\n return output;\n }, {});\n};\n\ninterface ValidateModelFieldsParams {\n models: CmsModel[];\n model: CmsModel;\n original?: CmsModel;\n context: CmsContext;\n}\n\nexport const validateModelFields = async (params: ValidateModelFieldsParams): Promise<void> => {\n const { models, model, original, context } = params;\n const { titleFieldId, descriptionFieldId, imageFieldId } = model;\n const { plugins } = context;\n\n /**\n * There should be fields/locked fields in either model or data to be updated.\n */\n const { fields = [], lockedFields = [] } = model;\n\n /**\n * Let's inspect the fields of the received content model. We prevent saving of a content model if it\n * contains a field for which a \"cms-model-field-to-graphql\" plugin does not exist on the backend.\n */\n const fieldTypePlugins = plugins.byType<CmsModelFieldToGraphQLPlugin>(\n \"cms-model-field-to-graphql\"\n );\n\n validateFields({\n fields,\n originalFields: original?.fields || [],\n lockedFields,\n plugins: fieldTypePlugins\n });\n\n if (fields.length) {\n const sorterPlugins = plugins.byType<CmsGraphQLSchemaSorterPlugin>(\n CmsGraphQLSchemaSorterPlugin.type\n );\n /**\n * Make sure that this model can be safely converted to a GraphQL SDL\n */\n const schema = createManageSDL({\n models,\n model,\n fieldTypePlugins: fieldTypePlugins.reduce(\n (acc, pl) => ({ ...acc, [pl.fieldType]: pl }),\n {}\n ),\n sorterPlugins\n });\n\n try {\n gql(schema);\n } catch (err) {\n throw new WebinyError(extractInvalidField(model, err));\n }\n /**\n *\n */\n try {\n await createGraphQLSchema({\n context,\n model\n });\n } catch (err) {\n throw new WebinyError({\n message:\n \"Cannot generate GraphQL schema when testing with the given model. Please check the response for more details.\",\n code: \"GRAPHQL_SCHEMA_ERROR\",\n data: {\n modelId: model.modelId,\n error: extractErrorObject(err)\n }\n });\n }\n }\n\n model.titleFieldId = getContentModelTitleFieldId(fields, titleFieldId);\n model.descriptionFieldId = getContentModelDescriptionFieldId(fields, descriptionFieldId);\n model.imageFieldId = getContentModelImageFieldId(fields, imageFieldId);\n\n const cmsLockedFieldPlugins =\n plugins.byType<CmsModelLockedFieldPlugin>(\"cms-model-locked-field\");\n\n /**\n * We must not allow removal or changes in fields that are already in use in content entries.\n * Locked fields still have fieldId (should be storageId) because of the old existing locked fields in the models.\n */\n for (const lockedField of lockedFields) {\n const existingField = fields.find(item => item.storageId === lockedField.fieldId);\n\n /**\n * Starting with 5.33.0 fields can be deleted.\n * Our UI gives a warning upon locked field deletion, but if user is managing fields through API directly - we cannot do anything.\n */\n if (!existingField) {\n continue;\n }\n\n if (Boolean(lockedField.multipleValues) !== Boolean(existingField.multipleValues)) {\n throw new WebinyError(\n `Cannot change \"multipleValues\" for the \"${lockedField.fieldId}\" field because it's already in use in created content.`,\n \"ENTRY_FIELD_USED\",\n {\n reason: `\"multipleValues\" changed`,\n field: existingField\n }\n );\n }\n\n const fieldType = getBaseFieldType(existingField);\n if (lockedField.type !== fieldType) {\n throw new WebinyError(\n `Cannot change field type for the \"${lockedField.fieldId}\" field because it's already in use in created content.`,\n \"ENTRY_FIELD_USED\",\n {\n reason: `\"type\" changed`,\n lockedFieldType: lockedField.type,\n existingFieldType: fieldType\n }\n );\n }\n\n /**\n * Check `lockedField` invariant for specific field\n */\n const lockedFieldsByType = cmsLockedFieldPlugins.filter(\n pl => pl.fieldType === getBaseFieldType(lockedField)\n );\n for (const plugin of lockedFieldsByType) {\n if (typeof plugin.checkLockedField !== \"function\") {\n continue;\n }\n plugin.checkLockedField({\n lockedField,\n field: existingField\n });\n }\n }\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AAUA,IAAAE,gBAAA,GAAAF,OAAA;AACA,IAAAG,qBAAA,GAAAH,OAAA;AAEA,IAAAI,iBAAA,GAAAJ,OAAA;AACA,IAAAK,WAAA,GAAAL,OAAA;AACA,IAAAM,iBAAA,GAAAN,OAAA;AACA,IAAAO,WAAA,GAAAP,OAAA;AACA,IAAAQ,QAAA,GAAAR,OAAA;AACA,IAAAS,mBAAA,GAAAT,OAAA;AACA,IAAAU,uBAAA,GAAAV,OAAA;AACA,IAAAW,MAAA,GAAAX,OAAA;AAEA,MAAMY,mBAAmB,GAAGA,CAACC,KAAe,EAAEC,GAAiB,KAAK;EAChE,MAAMC,GAAG,GAAGD,GAAG,CAACE,MAAM,EAAEC,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