@webiny/api-headless-cms 0.0.0-unstable.5e7233243f → 0.0.0-unstable.606fc9c866
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/context.d.ts +5 -2
- package/context.js +63 -29
- package/context.js.map +1 -1
- package/crud/contentEntry/afterDelete.d.ts +2 -2
- package/crud/contentEntry/afterDelete.js +2 -7
- package/crud/contentEntry/afterDelete.js.map +1 -1
- package/crud/contentEntry/beforeCreate.d.ts +2 -2
- package/crud/contentEntry/beforeCreate.js +2 -5
- package/crud/contentEntry/beforeCreate.js.map +1 -1
- package/crud/contentEntry/beforeUpdate.d.ts +2 -2
- package/crud/contentEntry/beforeUpdate.js +2 -5
- package/crud/contentEntry/beforeUpdate.js.map +1 -1
- package/crud/contentEntry/entryDataValidation.js +4 -47
- package/crud/contentEntry/entryDataValidation.js.map +1 -1
- package/crud/contentEntry/markLockedFields.d.ts +1 -1
- package/crud/contentEntry/markLockedFields.js +25 -39
- package/crud/contentEntry/markLockedFields.js.map +1 -1
- package/crud/contentEntry/referenceFieldsMapping.js +48 -77
- package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
- package/crud/contentEntry/searchableFields.d.ts +9 -0
- package/crud/contentEntry/searchableFields.js +72 -0
- package/crud/contentEntry/searchableFields.js.map +1 -0
- package/crud/contentEntry.crud.d.ts +8 -7
- package/crud/contentEntry.crud.js +1002 -1022
- package/crud/contentEntry.crud.js.map +1 -1
- package/crud/contentModel/afterCreate.d.ts +3 -3
- package/crud/contentModel/afterCreate.js +5 -7
- package/crud/contentModel/afterCreate.js.map +1 -1
- package/crud/contentModel/afterCreateFrom.d.ts +3 -3
- package/crud/contentModel/afterCreateFrom.js +5 -7
- package/crud/contentModel/afterCreateFrom.js.map +1 -1
- package/crud/contentModel/afterDelete.d.ts +3 -3
- package/crud/contentModel/afterDelete.js +5 -7
- package/crud/contentModel/afterDelete.js.map +1 -1
- package/crud/contentModel/afterUpdate.d.ts +3 -3
- package/crud/contentModel/afterUpdate.js +5 -7
- package/crud/contentModel/afterUpdate.js.map +1 -1
- package/crud/contentModel/beforeCreate.d.ts +5 -6
- package/crud/contentModel/beforeCreate.js +53 -119
- package/crud/contentModel/beforeCreate.js.map +1 -1
- package/crud/contentModel/beforeDelete.d.ts +3 -3
- package/crud/contentModel/beforeDelete.js +7 -21
- package/crud/contentModel/beforeDelete.js.map +1 -1
- package/crud/contentModel/beforeUpdate.d.ts +4 -6
- package/crud/contentModel/beforeUpdate.js +38 -15
- package/crud/contentModel/beforeUpdate.js.map +1 -1
- package/crud/contentModel/compatibility/modelApiName.d.ts +3 -0
- package/crud/contentModel/compatibility/modelApiName.js +24 -0
- package/crud/contentModel/compatibility/modelApiName.js.map +1 -0
- package/crud/contentModel/contentModelManagerFactory.js +0 -7
- package/crud/contentModel/contentModelManagerFactory.js.map +1 -1
- package/crud/contentModel/createFieldStorageId.js +4 -3
- package/crud/contentModel/createFieldStorageId.js.map +1 -1
- package/crud/contentModel/defaultFields.d.ts +5 -0
- package/crud/contentModel/defaultFields.js +58 -0
- package/crud/contentModel/defaultFields.js.map +1 -0
- package/crud/contentModel/fields/descriptionField.d.ts +2 -0
- package/crud/contentModel/fields/descriptionField.js +42 -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 +46 -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 +58 -0
- package/crud/contentModel/fields/titleField.js.map +1 -0
- package/crud/contentModel/validate/endingAllowed.d.ts +6 -0
- package/crud/contentModel/validate/endingAllowed.js +26 -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 +24 -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 +36 -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 +24 -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 +24 -0
- package/crud/contentModel/validate/singularApiName.js.map +1 -0
- package/crud/contentModel/validateLayout.js +0 -8
- package/crud/contentModel/validateLayout.js.map +1 -1
- package/crud/contentModel/validateModel.d.ts +4 -4
- package/crud/contentModel/validateModel.js +7 -12
- package/crud/contentModel/validateModel.js.map +1 -1
- package/crud/contentModel/validateModelFields.d.ts +4 -4
- package/crud/contentModel/validateModelFields.js +133 -154
- package/crud/contentModel/validateModelFields.js.map +1 -1
- package/crud/contentModel/validation.d.ts +551 -0
- package/crud/contentModel/validation.js +145 -0
- package/crud/contentModel/validation.js.map +1 -0
- package/crud/contentModel.crud.js +410 -375
- package/crud/contentModel.crud.js.map +1 -1
- package/crud/contentModelGroup/beforeCreate.d.ts +2 -2
- package/crud/contentModelGroup/beforeCreate.js +3 -15
- package/crud/contentModelGroup/beforeCreate.js.map +1 -1
- package/crud/contentModelGroup/beforeDelete.d.ts +2 -2
- package/crud/contentModelGroup/beforeDelete.js +3 -11
- package/crud/contentModelGroup/beforeDelete.js.map +1 -1
- package/crud/contentModelGroup/beforeUpdate.d.ts +2 -2
- package/crud/contentModelGroup/beforeUpdate.js +2 -7
- package/crud/contentModelGroup/beforeUpdate.js.map +1 -1
- package/crud/contentModelGroup/validation.d.ts +30 -0
- package/crud/contentModelGroup/validation.js +34 -0
- package/crud/contentModelGroup/validation.js.map +1 -0
- package/crud/contentModelGroup.crud.js +227 -221
- package/crud/contentModelGroup.crud.js.map +1 -1
- package/crud/settings.crud.d.ts +1 -1
- package/crud/settings.crud.js +8 -30
- package/crud/settings.crud.js.map +1 -1
- package/crud/system.crud.js +55 -138
- package/crud/system.crud.js.map +1 -1
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +1 -14
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.d.ts +11 -0
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +203 -0
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -0
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +16 -71
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/index.d.ts +2 -1
- package/fieldConverters/index.js +2 -5
- package/fieldConverters/index.js.map +1 -1
- package/graphql/buildSchemaPlugins.d.ts +8 -3
- package/graphql/buildSchemaPlugins.js +6 -14
- package/graphql/buildSchemaPlugins.js.map +1 -1
- package/graphql/checkEndpointAccess.d.ts +2 -0
- package/graphql/checkEndpointAccess.js +18 -0
- package/graphql/checkEndpointAccess.js.map +1 -0
- package/graphql/createExecutableSchema.d.ts +6 -0
- package/graphql/createExecutableSchema.js +29 -0
- package/graphql/createExecutableSchema.js.map +1 -0
- package/graphql/createRequestBody.d.ts +2 -0
- package/graphql/createRequestBody.js +14 -0
- package/graphql/createRequestBody.js.map +1 -0
- package/graphql/formatErrorPayload.d.ts +1 -0
- package/graphql/formatErrorPayload.js +25 -0
- package/graphql/formatErrorPayload.js.map +1 -0
- package/graphql/generateSchema.d.ts +8 -0
- package/graphql/generateSchema.js +31 -0
- package/graphql/generateSchema.js.map +1 -0
- package/graphql/getSchema.d.ts +17 -0
- package/graphql/getSchema.js +102 -0
- package/graphql/getSchema.js.map +1 -0
- package/graphql/graphQLHandlerFactory.js +7 -130
- package/graphql/graphQLHandlerFactory.js.map +1 -1
- package/graphql/handleRequest.d.ts +11 -0
- package/graphql/handleRequest.js +81 -0
- package/graphql/handleRequest.js.map +1 -0
- package/graphql/index.d.ts +1 -3
- package/graphql/index.js +2 -46
- package/graphql/index.js.map +1 -1
- package/graphql/schema/baseContentSchema.d.ts +6 -2
- package/graphql/schema/baseContentSchema.js +15 -29
- package/graphql/schema/baseContentSchema.js.map +1 -1
- package/graphql/schema/baseSchema.d.ts +3 -0
- package/graphql/schema/baseSchema.js +53 -0
- package/graphql/schema/baseSchema.js.map +1 -0
- package/graphql/schema/contentEntries.d.ts +6 -2
- package/graphql/schema/contentEntries.js +119 -108
- package/graphql/schema/contentEntries.js.map +1 -1
- package/graphql/schema/contentModelGroups.d.ts +6 -2
- package/graphql/schema/contentModelGroups.js +16 -29
- package/graphql/schema/contentModelGroups.js.map +1 -1
- package/graphql/schema/contentModels.d.ts +6 -2
- package/graphql/schema/contentModels.js +77 -22
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createFieldResolvers.d.ts +1 -1
- package/graphql/schema/createFieldResolvers.js +26 -38
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/graphql/schema/createManageResolvers.d.ts +1 -1
- package/graphql/schema/createManageResolvers.js +42 -60
- package/graphql/schema/createManageResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.d.ts +3 -0
- package/graphql/schema/createManageSDL.js +66 -73
- package/graphql/schema/createManageSDL.js.map +1 -1
- package/graphql/schema/createPreviewResolvers.js +6 -24
- package/graphql/schema/createPreviewResolvers.js.map +1 -1
- package/graphql/schema/createReadResolvers.js +11 -24
- package/graphql/schema/createReadResolvers.js.map +1 -1
- package/graphql/schema/createReadSDL.d.ts +3 -0
- package/graphql/schema/createReadSDL.js +33 -35
- package/graphql/schema/createReadSDL.js.map +1 -1
- package/graphql/schema/resolvers/commonFieldResolvers.d.ts +3 -2
- package/graphql/schema/resolvers/commonFieldResolvers.js +2 -3
- package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveCreate.js +0 -3
- package/graphql/schema/resolvers/manage/resolveCreate.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveCreateFrom.js +0 -3
- package/graphql/schema/resolvers/manage/resolveCreateFrom.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveDelete.js +0 -6
- package/graphql/schema/resolvers/manage/resolveDelete.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGet.js +5 -25
- package/graphql/schema/resolvers/manage/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGetByIds.js +0 -3
- package/graphql/schema/resolvers/manage/resolveGetByIds.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGetRevisions.js +0 -3
- 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 +18 -0
- package/graphql/schema/resolvers/manage/resolveGetUniqueFieldValues.js.map +1 -0
- package/graphql/schema/resolvers/manage/resolveList.js +0 -3
- package/graphql/schema/resolvers/manage/resolveList.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolvePublish.js +0 -3
- package/graphql/schema/resolvers/manage/resolvePublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveRepublish.js +0 -3
- package/graphql/schema/resolvers/manage/resolveRepublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveUnpublish.js +0 -3
- package/graphql/schema/resolvers/manage/resolveUnpublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveUpdate.js +0 -3
- package/graphql/schema/resolvers/manage/resolveUpdate.js.map +1 -1
- package/graphql/schema/resolvers/preview/resolveGet.js +3 -15
- package/graphql/schema/resolvers/preview/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/preview/resolveList.js +0 -3
- package/graphql/schema/resolvers/preview/resolveList.js.map +1 -1
- package/graphql/schema/resolvers/read/resolveGet.js +3 -15
- package/graphql/schema/resolvers/read/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/read/resolveList.js +0 -3
- package/graphql/schema/resolvers/read/resolveList.js.map +1 -1
- package/graphql/schema/schemaPlugins.d.ts +8 -3
- package/graphql/schema/schemaPlugins.js +64 -66
- package/graphql/schema/schemaPlugins.js.map +1 -1
- package/graphql/system.js +55 -87
- package/graphql/system.js.map +1 -1
- package/graphqlFields/boolean.js +0 -12
- package/graphqlFields/boolean.js.map +1 -1
- package/graphqlFields/datetime.js +0 -17
- package/graphqlFields/datetime.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +2 -0
- package/graphqlFields/dynamicZone/dynamicZoneField.js +243 -0
- package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.d.ts +3 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js +63 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js.map +1 -0
- package/graphqlFields/dynamicZone/index.d.ts +2 -0
- package/graphqlFields/dynamicZone/index.js +19 -0
- package/graphqlFields/dynamicZone/index.js.map +1 -0
- package/graphqlFields/file.js +0 -8
- package/graphqlFields/file.js.map +1 -1
- package/graphqlFields/helpers.js +0 -10
- package/graphqlFields/helpers.js.map +1 -1
- package/graphqlFields/index.d.ts +1 -1
- package/graphqlFields/index.js +2 -12
- package/graphqlFields/index.js.map +1 -1
- package/graphqlFields/longText.js +0 -10
- package/graphqlFields/longText.js.map +1 -1
- package/graphqlFields/number.js +4 -12
- package/graphqlFields/number.js.map +1 -1
- package/graphqlFields/object.js +132 -99
- package/graphqlFields/object.js.map +1 -1
- package/graphqlFields/ref.js +90 -114
- package/graphqlFields/ref.js.map +1 -1
- package/graphqlFields/richText.js +0 -9
- package/graphqlFields/richText.js.map +1 -1
- package/graphqlFields/text.js +0 -11
- package/graphqlFields/text.js.map +1 -1
- package/index.d.ts +5 -3
- package/index.js +27 -27
- package/index.js.map +1 -1
- package/modelManager/DefaultCmsModelManager.d.ts +7 -7
- package/modelManager/DefaultCmsModelManager.js +1 -17
- package/modelManager/DefaultCmsModelManager.js.map +1 -1
- package/modelManager/index.js +0 -4
- package/modelManager/index.js.map +1 -1
- package/package.json +30 -32
- package/parameters/context.js +0 -4
- package/parameters/context.js.map +1 -1
- package/parameters/header.js +1 -12
- package/parameters/header.js.map +1 -1
- package/parameters/index.js +0 -8
- package/parameters/index.js.map +1 -1
- package/parameters/manual.js +7 -15
- package/parameters/manual.js.map +1 -1
- package/parameters/path.js +1 -12
- package/parameters/path.js.map +1 -1
- package/plugins/CmsGraphQLSchemaPlugin.d.ts +5 -0
- package/plugins/CmsGraphQLSchemaPlugin.js +12 -0
- package/plugins/CmsGraphQLSchemaPlugin.js.map +1 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.d.ts +20 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.js +28 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.js.map +1 -0
- package/plugins/CmsGroupPlugin.js +1 -9
- package/plugins/CmsGroupPlugin.js.map +1 -1
- package/plugins/CmsModelFieldConverterPlugin.d.ts +2 -2
- package/plugins/CmsModelFieldConverterPlugin.js +1 -6
- package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
- package/plugins/CmsModelPlugin.d.ts +27 -5
- package/plugins/CmsModelPlugin.js +46 -51
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/plugins/CmsParametersPlugin.js +1 -8
- package/plugins/CmsParametersPlugin.js.map +1 -1
- package/plugins/StorageOperationsCmsModelPlugin.d.ts +23 -0
- package/plugins/StorageOperationsCmsModelPlugin.js +42 -0
- package/plugins/StorageOperationsCmsModelPlugin.js.map +1 -0
- package/plugins/StorageTransformPlugin.d.ts +11 -11
- package/plugins/StorageTransformPlugin.js +1 -10
- package/plugins/StorageTransformPlugin.js.map +1 -1
- package/plugins/index.d.ts +3 -0
- package/plugins/index.js +33 -10
- package/plugins/index.js.map +1 -1
- package/storage/default.js +0 -3
- package/storage/default.js.map +1 -1
- package/storage/object.js +7 -27
- package/storage/object.js.map +1 -1
- package/types.d.ts +642 -239
- package/types.js +67 -72
- package/types.js.map +1 -1
- package/utils/access.js +11 -25
- package/utils/access.js.map +1 -1
- package/utils/converters/Converter.js +1 -14
- package/utils/converters/Converter.js.map +1 -1
- package/utils/converters/ConverterCollection.d.ts +7 -0
- package/utils/converters/ConverterCollection.js +36 -32
- package/utils/converters/ConverterCollection.js.map +1 -1
- package/utils/converters/valueKeyStorageConverter.d.ts +1 -5
- package/utils/converters/valueKeyStorageConverter.js +23 -50
- package/utils/converters/valueKeyStorageConverter.js.map +1 -1
- package/utils/createTypeFromFields.d.ts +16 -0
- package/utils/createTypeFromFields.js +66 -0
- package/utils/createTypeFromFields.js.map +1 -0
- package/utils/createTypeName.d.ts +0 -2
- package/utils/createTypeName.js +5 -20
- package/utils/createTypeName.js.map +1 -1
- package/utils/entryStorage.js +25 -42
- package/utils/entryStorage.js.map +1 -1
- package/utils/filterAsync.js +0 -5
- package/utils/filterAsync.js.map +1 -1
- package/utils/getBaseFieldType.d.ts +4 -0
- package/utils/getBaseFieldType.js +10 -0
- package/utils/getBaseFieldType.js.map +1 -0
- package/utils/getEntryDescription.d.ts +2 -0
- package/utils/getEntryDescription.js +17 -0
- package/utils/getEntryDescription.js.map +1 -0
- package/utils/getEntryImage.d.ts +2 -0
- package/utils/getEntryImage.js +17 -0
- package/utils/getEntryImage.js.map +1 -0
- package/utils/getEntryTitle.js +0 -9
- package/utils/getEntryTitle.js.map +1 -1
- package/utils/getSchemaFromFieldPlugins.d.ts +4 -7
- package/utils/getSchemaFromFieldPlugins.js +23 -19
- package/utils/getSchemaFromFieldPlugins.js.map +1 -1
- package/utils/incrementEntryIdVersion.d.ts +5 -0
- package/utils/incrementEntryIdVersion.js +29 -0
- package/utils/incrementEntryIdVersion.js.map +1 -0
- package/utils/ownership.d.ts +3 -3
- package/utils/ownership.js +0 -8
- package/utils/ownership.js.map +1 -1
- package/utils/permissions.js +7 -26
- package/utils/permissions.js.map +1 -1
- package/utils/renderFields.d.ts +2 -1
- package/utils/renderFields.js +10 -10
- package/utils/renderFields.js.map +1 -1
- package/utils/renderGetFilterFields.js +6 -14
- package/utils/renderGetFilterFields.js.map +1 -1
- package/utils/renderInputFields.d.ts +2 -1
- package/utils/renderInputFields.js +6 -9
- package/utils/renderInputFields.js.map +1 -1
- package/utils/renderListFilterFields.js +10 -9
- package/utils/renderListFilterFields.js.map +1 -1
- package/utils/renderSortEnum.d.ts +7 -4
- package/utils/renderSortEnum.js +21 -11
- package/utils/renderSortEnum.js.map +1 -1
- package/utils/toSlug.js +1 -5
- package/utils/toSlug.js.map +1 -1
- package/validators/dateGte.js +0 -7
- package/validators/dateGte.js.map +1 -1
- package/validators/dateLte.js +0 -7
- package/validators/dateLte.js.map +1 -1
- package/validators/dynamicZone.d.ts +2 -0
- package/validators/dynamicZone.js +20 -0
- package/validators/dynamicZone.js.map +1 -0
- package/validators/gte.js +0 -8
- package/validators/gte.js.map +1 -1
- package/validators/in.js +0 -8
- package/validators/in.js.map +1 -1
- package/validators/index.js +2 -16
- package/validators/index.js.map +1 -1
- package/validators/lte.js +0 -8
- package/validators/lte.js.map +1 -1
- package/validators/maxLength.js +0 -8
- package/validators/maxLength.js.map +1 -1
- package/validators/minLength.js +0 -8
- package/validators/minLength.js.map +1 -1
- package/validators/pattern.js +0 -9
- package/validators/pattern.js.map +1 -1
- package/validators/patternPlugins/email.js +0 -2
- package/validators/patternPlugins/email.js.map +1 -1
- package/validators/patternPlugins/index.js +0 -8
- package/validators/patternPlugins/index.js.map +1 -1
- package/validators/patternPlugins/lowerCase.js +0 -2
- package/validators/patternPlugins/lowerCase.js.map +1 -1
- package/validators/patternPlugins/lowerCaseSpace.js +0 -2
- package/validators/patternPlugins/lowerCaseSpace.js.map +1 -1
- package/validators/patternPlugins/upperCase.js +0 -2
- package/validators/patternPlugins/upperCase.js.map +1 -1
- package/validators/patternPlugins/upperCaseSpace.js +0 -2
- package/validators/patternPlugins/upperCaseSpace.js.map +1 -1
- package/validators/patternPlugins/url.js +0 -2
- package/validators/patternPlugins/url.js.map +1 -1
- package/validators/required.js +0 -5
- package/validators/required.js.map +1 -1
- package/validators/timeGte.js +0 -8
- package/validators/timeGte.js.map +1 -1
- package/validators/timeLte.js +0 -8
- package/validators/timeLte.js.map +1 -1
- package/validators/unique.js +1 -8
- package/validators/unique.js.map +1 -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 -180
- 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/index.d.ts +0 -6
- package/crud/index.js +0 -89
- package/crud/index.js.map +0 -1
- package/graphql/schema/resolvers/manage/resolveRequestChanges.d.ts +0 -7
- package/graphql/schema/resolvers/manage/resolveRequestChanges.js +0 -21
- package/graphql/schema/resolvers/manage/resolveRequestChanges.js.map +0 -1
- package/graphql/schema/resolvers/manage/resolveRequestReview.d.ts +0 -7
- package/graphql/schema/resolvers/manage/resolveRequestReview.js +0 -21
- package/graphql/schema/resolvers/manage/resolveRequestReview.js.map +0 -1
- package/upgrades/5.33.0/index.d.ts +0 -3
- package/upgrades/5.33.0/index.js +0 -186
- package/upgrades/5.33.0/index.js.map +0 -1
- package/upgrades/index.d.ts +0 -1
- package/upgrades/index.js +0 -12
- package/upgrades/index.js.map +0 -1
- package/utils/filterModelFields.d.ts +0 -16
- package/utils/filterModelFields.js +0 -81
- package/utils/filterModelFields.js.map +0 -1
- package/utils/pluralizedTypeName.d.ts +0 -1
- package/utils/pluralizedTypeName.js +0 -26
- package/utils/pluralizedTypeName.js.map +0 -1
|
@@ -1,61 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
exports.createContentEntryCrud = exports.STATUS_UNPUBLISHED = exports.
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
|
|
7
|
+
exports.createContentEntryCrud = exports.STATUS_UNPUBLISHED = exports.STATUS_PUBLISHED = exports.STATUS_DRAFT = void 0;
|
|
8
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
+
var _merge = _interopRequireDefault(require("lodash/merge"));
|
|
12
10
|
var _mdbid = _interopRequireDefault(require("mdbid"));
|
|
13
|
-
|
|
11
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
14
12
|
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
15
|
-
|
|
13
|
+
var _types = require("../types");
|
|
16
14
|
var _entryDataValidation = require("./contentEntry/entryDataValidation");
|
|
17
|
-
|
|
18
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
19
|
-
|
|
20
15
|
var _pubsub = require("@webiny/pubsub");
|
|
21
|
-
|
|
22
16
|
var _beforeCreate = require("./contentEntry/beforeCreate");
|
|
23
|
-
|
|
24
17
|
var _beforeUpdate = require("./contentEntry/beforeUpdate");
|
|
25
|
-
|
|
26
18
|
var _utils = require("@webiny/utils");
|
|
27
|
-
|
|
28
19
|
var _afterDelete = require("./contentEntry/afterDelete");
|
|
29
|
-
|
|
30
20
|
var _referenceFieldsMapping = require("./contentEntry/referenceFieldsMapping");
|
|
31
|
-
|
|
32
|
-
var _merge = _interopRequireDefault(require("lodash/merge"));
|
|
33
|
-
|
|
34
21
|
var _permissions = require("../utils/permissions");
|
|
35
|
-
|
|
36
22
|
var _access = require("../utils/access");
|
|
37
|
-
|
|
38
23
|
var _ownership = require("../utils/ownership");
|
|
39
|
-
|
|
40
24
|
var _entryStorage = require("../utils/entryStorage");
|
|
25
|
+
var _searchableFields = require("./contentEntry/searchableFields");
|
|
26
|
+
/**
|
|
27
|
+
* Package mdbid does not have types.
|
|
28
|
+
*/
|
|
29
|
+
// @ts-ignore
|
|
41
30
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
45
|
-
|
|
46
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
47
|
-
|
|
48
|
-
const STATUS_DRAFT = "draft";
|
|
31
|
+
const STATUS_DRAFT = _types.CONTENT_ENTRY_STATUS.DRAFT;
|
|
49
32
|
exports.STATUS_DRAFT = STATUS_DRAFT;
|
|
50
|
-
const STATUS_PUBLISHED =
|
|
33
|
+
const STATUS_PUBLISHED = _types.CONTENT_ENTRY_STATUS.PUBLISHED;
|
|
51
34
|
exports.STATUS_PUBLISHED = STATUS_PUBLISHED;
|
|
52
|
-
const STATUS_UNPUBLISHED =
|
|
35
|
+
const STATUS_UNPUBLISHED = _types.CONTENT_ENTRY_STATUS.UNPUBLISHED;
|
|
53
36
|
exports.STATUS_UNPUBLISHED = STATUS_UNPUBLISHED;
|
|
54
|
-
const STATUS_CHANGES_REQUESTED = "changesRequested";
|
|
55
|
-
exports.STATUS_CHANGES_REQUESTED = STATUS_CHANGES_REQUESTED;
|
|
56
|
-
const STATUS_REVIEW_REQUESTED = "reviewRequested";
|
|
57
|
-
exports.STATUS_REVIEW_REQUESTED = STATUS_REVIEW_REQUESTED;
|
|
58
|
-
|
|
59
37
|
/**
|
|
60
38
|
* Used for some fields to convert their values.
|
|
61
39
|
*/
|
|
@@ -63,45 +41,35 @@ const convertDefaultValue = (field, value) => {
|
|
|
63
41
|
switch (field.type) {
|
|
64
42
|
case "boolean":
|
|
65
43
|
return Boolean(value);
|
|
66
|
-
|
|
67
44
|
case "number":
|
|
68
45
|
return Number(value);
|
|
69
|
-
|
|
70
46
|
default:
|
|
71
47
|
return value;
|
|
72
48
|
}
|
|
73
49
|
};
|
|
74
|
-
|
|
75
50
|
const getDefaultValue = field => {
|
|
76
51
|
const {
|
|
77
52
|
settings,
|
|
78
53
|
multipleValues
|
|
79
54
|
} = field;
|
|
80
|
-
|
|
81
55
|
if (settings && settings.defaultValue !== undefined) {
|
|
82
56
|
return convertDefaultValue(field, settings.defaultValue);
|
|
83
57
|
}
|
|
84
|
-
|
|
85
58
|
const {
|
|
86
59
|
predefinedValues
|
|
87
60
|
} = field;
|
|
88
|
-
|
|
89
61
|
if (!predefinedValues || !predefinedValues.enabled || Array.isArray(predefinedValues.values) === false) {
|
|
90
62
|
return undefined;
|
|
91
63
|
}
|
|
92
|
-
|
|
93
64
|
if (!multipleValues) {
|
|
94
65
|
const selectedValue = predefinedValues.values.find(value => {
|
|
95
66
|
return !!value.selected;
|
|
96
67
|
});
|
|
97
|
-
|
|
98
68
|
if (selectedValue) {
|
|
99
69
|
return convertDefaultValue(field, selectedValue.value);
|
|
100
70
|
}
|
|
101
|
-
|
|
102
71
|
return undefined;
|
|
103
72
|
}
|
|
104
|
-
|
|
105
73
|
return predefinedValues.values.filter(({
|
|
106
74
|
selected
|
|
107
75
|
}) => !!selected).map(({
|
|
@@ -113,8 +81,6 @@ const getDefaultValue = field => {
|
|
|
113
81
|
/**
|
|
114
82
|
* Cleans and adds default values to create input data.
|
|
115
83
|
*/
|
|
116
|
-
|
|
117
|
-
|
|
118
84
|
const mapAndCleanCreateInputData = (model, input) => {
|
|
119
85
|
return model.fields.reduce((acc, field) => {
|
|
120
86
|
/**
|
|
@@ -126,12 +92,10 @@ const mapAndCleanCreateInputData = (model, input) => {
|
|
|
126
92
|
field
|
|
127
93
|
});
|
|
128
94
|
}
|
|
129
|
-
|
|
130
95
|
const value = input[field.fieldId];
|
|
131
96
|
/**
|
|
132
97
|
* We set the default value on create input if value is not defined.
|
|
133
98
|
*/
|
|
134
|
-
|
|
135
99
|
acc[field.fieldId] = value === undefined ? getDefaultValue(field) : value;
|
|
136
100
|
return acc;
|
|
137
101
|
}, {});
|
|
@@ -139,8 +103,6 @@ const mapAndCleanCreateInputData = (model, input) => {
|
|
|
139
103
|
/**
|
|
140
104
|
* Cleans the update input entry data.
|
|
141
105
|
*/
|
|
142
|
-
|
|
143
|
-
|
|
144
106
|
const mapAndCleanUpdatedInputData = (model, input) => {
|
|
145
107
|
return model.fields.reduce((acc, field) => {
|
|
146
108
|
/**
|
|
@@ -155,14 +117,10 @@ const mapAndCleanUpdatedInputData = (model, input) => {
|
|
|
155
117
|
/**
|
|
156
118
|
* We cannot set default value here because user might want to update only certain field values.
|
|
157
119
|
*/
|
|
158
|
-
|
|
159
|
-
|
|
160
120
|
const value = input[field.fieldId];
|
|
161
|
-
|
|
162
121
|
if (value === undefined) {
|
|
163
122
|
return acc;
|
|
164
123
|
}
|
|
165
|
-
|
|
166
124
|
acc[field.fieldId] = value;
|
|
167
125
|
return acc;
|
|
168
126
|
}, {});
|
|
@@ -171,24 +129,21 @@ const mapAndCleanUpdatedInputData = (model, input) => {
|
|
|
171
129
|
* This method takes original entry meta and new input.
|
|
172
130
|
* When new meta is merged onto the existing one, everything that has undefined or null value is removed.
|
|
173
131
|
*/
|
|
174
|
-
|
|
175
|
-
|
|
176
132
|
const createEntryMeta = (input, original) => {
|
|
177
133
|
const meta = (0, _merge.default)(original || {}, input || {});
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
134
|
+
return (0, _utils.removeUndefinedValues)((0, _utils.removeNullValues)(meta));
|
|
135
|
+
};
|
|
136
|
+
const createEntryId = input => {
|
|
137
|
+
let entryId = (0, _mdbid.default)();
|
|
138
|
+
if (input.id) {
|
|
139
|
+
if (input.id.match(/^([a-zA-Z0-9])([a-zA-Z0-9\-]+)([a-zA-Z0-9])$/) === null) {
|
|
140
|
+
throw new _error.default("The provided ID is not valid. It must be a string which can be A-Z, a-z, 0-9, - and it cannot start or end with a -.", "INVALID_ID", {
|
|
141
|
+
id: input.id
|
|
142
|
+
});
|
|
182
143
|
}
|
|
183
|
-
|
|
184
|
-
delete meta[key];
|
|
144
|
+
entryId = input.id;
|
|
185
145
|
}
|
|
186
|
-
|
|
187
|
-
return meta;
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
const createEntryId = version => {
|
|
191
|
-
const entryId = (0, _mdbid.default)();
|
|
146
|
+
const version = 1;
|
|
192
147
|
return {
|
|
193
148
|
entryId,
|
|
194
149
|
version,
|
|
@@ -198,19 +153,16 @@ const createEntryId = version => {
|
|
|
198
153
|
})
|
|
199
154
|
};
|
|
200
155
|
};
|
|
201
|
-
|
|
202
156
|
const increaseEntryIdVersion = id => {
|
|
203
157
|
const {
|
|
204
158
|
id: entryId,
|
|
205
159
|
version
|
|
206
160
|
} = (0, _utils.parseIdentifier)(id);
|
|
207
|
-
|
|
208
161
|
if (!version) {
|
|
209
162
|
throw new _error.default("Cannot increase version on the ID without the version part.", "WRONG_ID", {
|
|
210
163
|
id
|
|
211
164
|
});
|
|
212
165
|
}
|
|
213
|
-
|
|
214
166
|
return {
|
|
215
167
|
entryId,
|
|
216
168
|
version: version + 1,
|
|
@@ -220,1078 +172,1106 @@ const increaseEntryIdVersion = id => {
|
|
|
220
172
|
})
|
|
221
173
|
};
|
|
222
174
|
};
|
|
223
|
-
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
plugins,
|
|
227
|
-
model,
|
|
228
|
-
fields
|
|
229
|
-
} = params;
|
|
230
|
-
const fieldPluginMap = plugins.byType("cms-model-field-to-graphql").reduce((collection, field) => {
|
|
231
|
-
collection[field.fieldType] = field;
|
|
232
|
-
return collection;
|
|
233
|
-
}, {});
|
|
234
|
-
return model.fields.filter(field => {
|
|
235
|
-
if (!field.fieldId) {
|
|
236
|
-
return false;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
const plugin = fieldPluginMap[field.type];
|
|
240
|
-
|
|
241
|
-
if (!plugin) {
|
|
242
|
-
return false;
|
|
243
|
-
} else if (!plugin.fullTextSearch) {
|
|
244
|
-
return false;
|
|
245
|
-
} else if (!fields || fields.length === 0) {
|
|
246
|
-
return true;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
return fields.includes(field.fieldId);
|
|
250
|
-
}).map(field => field.fieldId);
|
|
175
|
+
const allowedEntryStatus = ["draft", "published", "unpublished"];
|
|
176
|
+
const transformEntryStatus = status => {
|
|
177
|
+
return allowedEntryStatus.includes(status) ? status : "draft";
|
|
251
178
|
};
|
|
252
|
-
|
|
253
179
|
const createContentEntryCrud = params => {
|
|
254
180
|
const {
|
|
255
181
|
storageOperations,
|
|
256
182
|
context,
|
|
257
183
|
getIdentity,
|
|
258
|
-
getTenant
|
|
184
|
+
getTenant,
|
|
185
|
+
getLocale
|
|
259
186
|
} = params;
|
|
260
|
-
const {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
const onBeforeEntryPublish = (0, _pubsub.createTopic)();
|
|
270
|
-
const onAfterEntryPublish = (0, _pubsub.createTopic)();
|
|
271
|
-
const onBeforeEntryUnpublish = (0, _pubsub.createTopic)();
|
|
272
|
-
const onAfterEntryUnpublish = (0, _pubsub.createTopic)();
|
|
273
|
-
const onBeforeEntryRequestChanges = (0, _pubsub.createTopic)();
|
|
274
|
-
const onAfterEntryRequestChanges = (0, _pubsub.createTopic)();
|
|
275
|
-
const onBeforeEntryRequestReview = (0, _pubsub.createTopic)();
|
|
276
|
-
const onAfterEntryRequestReview = (0, _pubsub.createTopic)();
|
|
277
|
-
const onBeforeEntryDelete = (0, _pubsub.createTopic)();
|
|
278
|
-
const onAfterEntryDelete = (0, _pubsub.createTopic)();
|
|
279
|
-
const onBeforeEntryDeleteRevision = (0, _pubsub.createTopic)();
|
|
280
|
-
const onAfterEntryDeleteRevision = (0, _pubsub.createTopic)();
|
|
281
|
-
const onBeforeEntryGet = (0, _pubsub.createTopic)();
|
|
282
|
-
const onBeforeEntryList = (0, _pubsub.createTopic)();
|
|
187
|
+
const getCreatedBy = () => {
|
|
188
|
+
const identity = getIdentity();
|
|
189
|
+
return {
|
|
190
|
+
id: identity.id,
|
|
191
|
+
displayName: identity.displayName,
|
|
192
|
+
type: identity.type
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
|
|
283
196
|
/**
|
|
284
|
-
*
|
|
197
|
+
* Create
|
|
198
|
+
*/
|
|
199
|
+
const onEntryBeforeCreate = (0, _pubsub.createTopic)("cms.onEntryBeforeCreate");
|
|
200
|
+
const onEntryAfterCreate = (0, _pubsub.createTopic)("cms.onEntryAfterCreate");
|
|
201
|
+
const onEntryCreateError = (0, _pubsub.createTopic)("cms.onEntryCreateError");
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Create new revision
|
|
205
|
+
*/
|
|
206
|
+
const onEntryBeforeCreateRevision = (0, _pubsub.createTopic)("cms.onEntryBeforeCreateRevision");
|
|
207
|
+
const onEntryRevisionAfterCreate = (0, _pubsub.createTopic)("cms.onEntryRevisionAfterCreate");
|
|
208
|
+
const onEntryCreateRevisionError = (0, _pubsub.createTopic)("cms.onEntryCreateRevisionError");
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Update
|
|
212
|
+
*/
|
|
213
|
+
const onEntryBeforeUpdate = (0, _pubsub.createTopic)("cms.onEntryBeforeUpdate");
|
|
214
|
+
const onEntryAfterUpdate = (0, _pubsub.createTopic)("cms.onEntryAfterUpdate");
|
|
215
|
+
const onEntryUpdateError = (0, _pubsub.createTopic)("cms.onEntryUpdateError");
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Publish
|
|
219
|
+
*/
|
|
220
|
+
const onEntryBeforePublish = (0, _pubsub.createTopic)("cms.onEntryBeforePublish");
|
|
221
|
+
const onEntryAfterPublish = (0, _pubsub.createTopic)("cms.onEntryAfterPublish");
|
|
222
|
+
const onEntryPublishError = (0, _pubsub.createTopic)("cms.onEntryPublishError");
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Republish
|
|
226
|
+
*/
|
|
227
|
+
const onEntryBeforeRepublish = (0, _pubsub.createTopic)("cms.onEntryBeforeRepublish");
|
|
228
|
+
const onEntryAfterRepublish = (0, _pubsub.createTopic)("cms.onEntryAfterRepublish");
|
|
229
|
+
const onEntryRepublishError = (0, _pubsub.createTopic)("cms.onEntryRepublishError");
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Unpublish
|
|
233
|
+
*/
|
|
234
|
+
const onEntryBeforeUnpublish = (0, _pubsub.createTopic)("cms.onEntryBeforeUnpublish");
|
|
235
|
+
const onEntryAfterUnpublish = (0, _pubsub.createTopic)("cms.onEntryAfterUnpublish");
|
|
236
|
+
const onEntryUnpublishError = (0, _pubsub.createTopic)("cms.onEntryUnpublishError");
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Delete
|
|
240
|
+
*/
|
|
241
|
+
const onEntryBeforeDelete = (0, _pubsub.createTopic)("cms.onEntryBeforeDelete");
|
|
242
|
+
const onEntryAfterDelete = (0, _pubsub.createTopic)("cms.onEntryAfterDelete");
|
|
243
|
+
const onEntryDeleteError = (0, _pubsub.createTopic)("cms.onEntryDeleteError");
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Delete revision
|
|
247
|
+
*/
|
|
248
|
+
const onEntryRevisionBeforeDelete = (0, _pubsub.createTopic)("cms.onEntryRevisionBeforeDelete");
|
|
249
|
+
const onEntryRevisionAfterDelete = (0, _pubsub.createTopic)("cms.onEntryRevisionAfterDelete");
|
|
250
|
+
const onEntryRevisionDeleteError = (0, _pubsub.createTopic)("cms.onEntryRevisionDeleteError");
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Get entry
|
|
254
|
+
*/
|
|
255
|
+
const onEntryBeforeGet = (0, _pubsub.createTopic)("cms.onEntryBeforeGet");
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* List entries
|
|
285
259
|
*/
|
|
260
|
+
const onEntryBeforeList = (0, _pubsub.createTopic)("cms.onEntryBeforeList");
|
|
286
261
|
|
|
262
|
+
/**
|
|
263
|
+
* We need to assign some default behaviors.
|
|
264
|
+
*/
|
|
287
265
|
(0, _beforeCreate.assignBeforeEntryCreate)({
|
|
288
266
|
context,
|
|
289
|
-
|
|
267
|
+
onEntryBeforeCreate
|
|
290
268
|
});
|
|
291
269
|
(0, _beforeUpdate.assignBeforeEntryUpdate)({
|
|
292
270
|
context,
|
|
293
|
-
|
|
271
|
+
onEntryBeforeUpdate
|
|
294
272
|
});
|
|
295
273
|
(0, _afterDelete.assignAfterEntryDelete)({
|
|
296
274
|
context,
|
|
297
|
-
|
|
275
|
+
onEntryAfterDelete
|
|
298
276
|
});
|
|
299
|
-
|
|
300
277
|
const checkEntryPermissions = check => {
|
|
301
278
|
return (0, _permissions.checkPermissions)(context, "cms.contentEntry", check);
|
|
302
279
|
};
|
|
280
|
+
|
|
303
281
|
/**
|
|
304
282
|
* A helper to delete the entire entry.
|
|
305
283
|
*/
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
model,
|
|
311
|
-
entry
|
|
312
|
-
} = params;
|
|
313
|
-
|
|
314
|
-
try {
|
|
315
|
-
await onBeforeEntryDelete.publish({
|
|
316
|
-
entry,
|
|
317
|
-
model
|
|
318
|
-
});
|
|
319
|
-
await storageOperations.entries.delete(model, {
|
|
320
|
-
entry
|
|
321
|
-
});
|
|
322
|
-
await onAfterEntryDelete.publish({
|
|
323
|
-
entry,
|
|
324
|
-
model
|
|
325
|
-
});
|
|
326
|
-
} catch (ex) {
|
|
327
|
-
throw new _error.default(ex.message || "Could not delete entry.", ex.code || "DELETE_ERROR", {
|
|
284
|
+
const deleteEntryHelper = async params => {
|
|
285
|
+
return context.benchmark.measure("headlessCms.crud.entries.deleteEntry", async () => {
|
|
286
|
+
const {
|
|
287
|
+
model,
|
|
328
288
|
entry
|
|
329
|
-
}
|
|
330
|
-
|
|
289
|
+
} = params;
|
|
290
|
+
try {
|
|
291
|
+
await onEntryBeforeDelete.publish({
|
|
292
|
+
entry,
|
|
293
|
+
model
|
|
294
|
+
});
|
|
295
|
+
await storageOperations.entries.delete(model, {
|
|
296
|
+
entry
|
|
297
|
+
});
|
|
298
|
+
await onEntryAfterDelete.publish({
|
|
299
|
+
entry,
|
|
300
|
+
model
|
|
301
|
+
});
|
|
302
|
+
} catch (ex) {
|
|
303
|
+
await onEntryDeleteError.publish({
|
|
304
|
+
entry,
|
|
305
|
+
model,
|
|
306
|
+
error: ex
|
|
307
|
+
});
|
|
308
|
+
throw new _error.default(ex.message || "Could not delete entry.", ex.code || "DELETE_ERROR", {
|
|
309
|
+
entry
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
});
|
|
331
313
|
};
|
|
332
314
|
/**
|
|
333
315
|
* A helper to get entries by revision IDs
|
|
334
316
|
*/
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
317
|
+
const getEntriesByIds = async (model, ids) => {
|
|
318
|
+
return context.benchmark.measure("headlessCms.crud.entries.getEntriesByIds", async () => {
|
|
319
|
+
const permission = await checkEntryPermissions({
|
|
320
|
+
rwd: "r"
|
|
321
|
+
});
|
|
322
|
+
await (0, _access.checkModelAccess)(context, model);
|
|
323
|
+
const entries = await storageOperations.entries.getByIds(model, {
|
|
324
|
+
ids
|
|
325
|
+
});
|
|
326
|
+
return entries.filter(entry => (0, _ownership.validateOwnership)(context, permission, entry));
|
|
327
|
+
});
|
|
328
|
+
};
|
|
329
|
+
const getEntryById = async (model, id) => {
|
|
330
|
+
const where = {
|
|
331
|
+
id
|
|
332
|
+
};
|
|
333
|
+
await onEntryBeforeGet.publish({
|
|
334
|
+
where,
|
|
335
|
+
model
|
|
336
|
+
});
|
|
337
|
+
const [entry] = await getEntriesByIds(model, [id]);
|
|
338
|
+
if (!entry) {
|
|
339
|
+
throw new _handlerGraphql.NotFoundError(`Entry by ID "${id}" not found.`);
|
|
340
|
+
}
|
|
341
|
+
return entry;
|
|
342
|
+
};
|
|
343
|
+
const getPublishedEntriesByIds = async (model, ids) => {
|
|
338
344
|
const permission = await checkEntryPermissions({
|
|
339
345
|
rwd: "r"
|
|
340
346
|
});
|
|
341
|
-
await (0, _access.checkModelAccess)(context,
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
347
|
+
await (0, _access.checkModelAccess)(context, model);
|
|
348
|
+
const entries = await storageOperations.entries.getPublishedByIds(model, {
|
|
349
|
+
ids
|
|
350
|
+
});
|
|
351
|
+
return entries.filter(entry => (0, _ownership.validateOwnership)(context, permission, entry));
|
|
352
|
+
};
|
|
353
|
+
const getLatestEntriesByIds = async (model, ids) => {
|
|
354
|
+
const permission = await checkEntryPermissions({
|
|
355
|
+
rwd: "r"
|
|
345
356
|
});
|
|
346
|
-
|
|
357
|
+
await (0, _access.checkModelAccess)(context, model);
|
|
358
|
+
const entries = await storageOperations.entries.getLatestByIds(model, {
|
|
347
359
|
ids
|
|
348
360
|
});
|
|
349
361
|
return entries.filter(entry => (0, _ownership.validateOwnership)(context, permission, entry));
|
|
350
362
|
};
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
363
|
+
const getEntry = async (model, params) => {
|
|
364
|
+
await checkEntryPermissions({
|
|
365
|
+
rwd: "r"
|
|
366
|
+
});
|
|
367
|
+
const {
|
|
368
|
+
where,
|
|
369
|
+
sort
|
|
370
|
+
} = params;
|
|
371
|
+
await onEntryBeforeGet.publish({
|
|
372
|
+
where,
|
|
373
|
+
model
|
|
374
|
+
});
|
|
375
|
+
const [items] = await listEntries(model, {
|
|
376
|
+
where,
|
|
377
|
+
sort,
|
|
378
|
+
limit: 1
|
|
379
|
+
});
|
|
380
|
+
const item = items.shift();
|
|
381
|
+
if (!item) {
|
|
382
|
+
throw new _handlerGraphql.NotFoundError(`Entry not found!`);
|
|
383
|
+
}
|
|
384
|
+
return item;
|
|
385
|
+
};
|
|
386
|
+
const getEntryRevisions = async (model, entryId) => {
|
|
387
|
+
return storageOperations.entries.getRevisions(model, {
|
|
388
|
+
id: entryId
|
|
389
|
+
});
|
|
390
|
+
};
|
|
391
|
+
const listEntries = async (model, params) => {
|
|
392
|
+
const permission = await checkEntryPermissions({
|
|
393
|
+
rwd: "r"
|
|
394
|
+
});
|
|
395
|
+
await (0, _access.checkModelAccess)(context, model);
|
|
396
|
+
const {
|
|
397
|
+
where: initialWhere,
|
|
398
|
+
limit: initialLimit
|
|
399
|
+
} = params;
|
|
400
|
+
const limit = initialLimit && initialLimit > 0 ? initialLimit : 50;
|
|
401
|
+
const where = (0, _objectSpread2.default)({}, initialWhere);
|
|
374
402
|
/**
|
|
375
|
-
*
|
|
403
|
+
* Possibly only get records which are owned by current user.
|
|
404
|
+
* Or if searching for the owner set that value - in the case that user can see other entries than their own.
|
|
376
405
|
*/
|
|
377
|
-
|
|
378
|
-
|
|
406
|
+
const ownedBy = permission.own ? getIdentity().id : where.ownedBy;
|
|
407
|
+
if (ownedBy !== undefined) {
|
|
408
|
+
where.ownedBy = ownedBy;
|
|
409
|
+
}
|
|
379
410
|
/**
|
|
380
|
-
*
|
|
411
|
+
* Where must contain either latest or published keys.
|
|
412
|
+
* We cannot list entries without one of those
|
|
381
413
|
*/
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
};
|
|
386
|
-
const model = (0, _valueKeyStorageConverter.attachCmsModelFieldConverters)({
|
|
387
|
-
model: initialModel,
|
|
388
|
-
plugins
|
|
414
|
+
if (where.latest && where.published) {
|
|
415
|
+
throw new _error.default("Cannot list entries that are both published and latest.", "LIST_ENTRIES_ERROR", {
|
|
416
|
+
where
|
|
389
417
|
});
|
|
390
|
-
|
|
418
|
+
} else if (!where.latest && !where.published) {
|
|
419
|
+
throw new _error.default("Cannot list entries if we do not have latest or published defined.", "LIST_ENTRIES_ERROR", {
|
|
420
|
+
where
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
const fields = (0, _searchableFields.getSearchableFields)({
|
|
424
|
+
fields: model.fields,
|
|
425
|
+
plugins: context.plugins,
|
|
426
|
+
input: params.fields || []
|
|
427
|
+
});
|
|
428
|
+
try {
|
|
429
|
+
await onEntryBeforeList.publish({
|
|
391
430
|
where,
|
|
392
431
|
model
|
|
393
432
|
});
|
|
394
|
-
const
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
433
|
+
const {
|
|
434
|
+
hasMoreItems,
|
|
435
|
+
totalCount,
|
|
436
|
+
cursor,
|
|
437
|
+
items
|
|
438
|
+
} = await storageOperations.entries.list(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
439
|
+
limit,
|
|
440
|
+
where,
|
|
441
|
+
fields
|
|
442
|
+
}));
|
|
443
|
+
const meta = {
|
|
444
|
+
hasMoreItems,
|
|
445
|
+
totalCount,
|
|
446
|
+
/**
|
|
447
|
+
* Cursor should be null if there are no more items to load.
|
|
448
|
+
* Just make sure of that, disregarding what is returned from the storageOperations.entries.list method.
|
|
449
|
+
*/
|
|
450
|
+
cursor: hasMoreItems ? cursor : null
|
|
451
|
+
};
|
|
452
|
+
return [items, meta];
|
|
453
|
+
} catch (ex) {
|
|
454
|
+
throw new _error.default("Error while fetching entries from storage.", "LIST_ENTRIES_ERROR", {
|
|
455
|
+
params,
|
|
456
|
+
error: {
|
|
457
|
+
message: ex.message,
|
|
458
|
+
code: ex.code,
|
|
459
|
+
data: ex.data
|
|
460
|
+
},
|
|
461
|
+
model,
|
|
462
|
+
fields
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
const createEntry = async (model, inputData) => {
|
|
467
|
+
await checkEntryPermissions({
|
|
468
|
+
rwd: "w"
|
|
469
|
+
});
|
|
470
|
+
await (0, _access.checkModelAccess)(context, model);
|
|
402
471
|
|
|
403
472
|
/**
|
|
404
|
-
*
|
|
473
|
+
* Make sure we only work with fields that are defined in the model.
|
|
405
474
|
*/
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
475
|
+
const initialInput = mapAndCleanCreateInputData(model, inputData);
|
|
476
|
+
await (0, _entryDataValidation.validateModelEntryData)({
|
|
477
|
+
context,
|
|
478
|
+
model,
|
|
479
|
+
data: initialInput
|
|
480
|
+
});
|
|
481
|
+
const input = await (0, _referenceFieldsMapping.referenceFieldsMapping)({
|
|
482
|
+
context,
|
|
483
|
+
model,
|
|
484
|
+
input: initialInput,
|
|
485
|
+
validateEntries: true
|
|
486
|
+
});
|
|
487
|
+
const locale = getLocale();
|
|
488
|
+
const owner = getCreatedBy();
|
|
489
|
+
const {
|
|
490
|
+
id,
|
|
491
|
+
entryId,
|
|
492
|
+
version
|
|
493
|
+
} = createEntryId(inputData);
|
|
421
494
|
/**
|
|
422
|
-
*
|
|
495
|
+
* There is a possibility that user sends an ID in the input, so we will use that one.
|
|
496
|
+
* There is no check if the ID is unique or not, that is up to the user.
|
|
423
497
|
*/
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
498
|
+
const entry = {
|
|
499
|
+
webinyVersion: context.WEBINY_VERSION,
|
|
500
|
+
tenant: getTenant().id,
|
|
501
|
+
entryId,
|
|
502
|
+
id,
|
|
503
|
+
modelId: model.modelId,
|
|
504
|
+
locale: locale.code,
|
|
505
|
+
createdOn: new Date().toISOString(),
|
|
506
|
+
savedOn: new Date().toISOString(),
|
|
507
|
+
createdBy: owner,
|
|
508
|
+
ownedBy: owner,
|
|
509
|
+
modifiedBy: null,
|
|
510
|
+
version,
|
|
511
|
+
locked: false,
|
|
512
|
+
status: STATUS_DRAFT,
|
|
513
|
+
values: input
|
|
514
|
+
};
|
|
515
|
+
let storageEntry = null;
|
|
516
|
+
try {
|
|
517
|
+
await onEntryBeforeCreate.publish({
|
|
518
|
+
entry,
|
|
519
|
+
input,
|
|
520
|
+
model
|
|
427
521
|
});
|
|
428
|
-
await (0,
|
|
429
|
-
const
|
|
430
|
-
|
|
431
|
-
|
|
522
|
+
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
523
|
+
const result = await storageOperations.entries.create(model, {
|
|
524
|
+
entry,
|
|
525
|
+
storageEntry
|
|
432
526
|
});
|
|
433
|
-
|
|
434
|
-
|
|
527
|
+
await onEntryAfterCreate.publish({
|
|
528
|
+
entry,
|
|
529
|
+
storageEntry: result,
|
|
530
|
+
model,
|
|
531
|
+
input
|
|
435
532
|
});
|
|
436
|
-
return
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
533
|
+
return result;
|
|
534
|
+
} catch (ex) {
|
|
535
|
+
await onEntryCreateError.publish({
|
|
536
|
+
error: ex,
|
|
537
|
+
entry,
|
|
538
|
+
model,
|
|
539
|
+
input
|
|
442
540
|
});
|
|
443
|
-
|
|
444
|
-
|
|
541
|
+
throw new _error.default(ex.message || "Could not create content entry.", ex.code || "CREATE_ENTRY_ERROR", ex.data || {
|
|
542
|
+
error: ex,
|
|
543
|
+
input,
|
|
544
|
+
entry,
|
|
545
|
+
storageEntry
|
|
445
546
|
});
|
|
446
|
-
}
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
const createEntryRevisionFrom = async (model, sourceId, inputData) => {
|
|
550
|
+
const permission = await checkEntryPermissions({
|
|
551
|
+
rwd: "w"
|
|
552
|
+
});
|
|
553
|
+
await (0, _access.checkModelAccess)(context, model);
|
|
447
554
|
|
|
448
555
|
/**
|
|
449
|
-
*
|
|
450
|
-
*
|
|
451
|
-
* @internal
|
|
556
|
+
* Make sure we only work with fields that are defined in the model.
|
|
452
557
|
*/
|
|
453
|
-
|
|
454
|
-
await checkEntryPermissions({
|
|
455
|
-
rwd: "r"
|
|
456
|
-
});
|
|
457
|
-
const model = (0, _valueKeyStorageConverter.attachCmsModelFieldConverters)({
|
|
458
|
-
model: initialModel,
|
|
459
|
-
plugins
|
|
460
|
-
});
|
|
461
|
-
const {
|
|
462
|
-
where,
|
|
463
|
-
sort
|
|
464
|
-
} = params;
|
|
465
|
-
await onBeforeEntryGet.publish({
|
|
466
|
-
where,
|
|
467
|
-
model
|
|
468
|
-
});
|
|
469
|
-
const [items] = await context.cms.listEntries(model, {
|
|
470
|
-
where,
|
|
471
|
-
sort,
|
|
472
|
-
limit: 1
|
|
473
|
-
});
|
|
474
|
-
|
|
475
|
-
if (items.length === 0) {
|
|
476
|
-
throw new _handlerGraphql.NotFoundError(`Entry not found!`);
|
|
477
|
-
}
|
|
558
|
+
const input = mapAndCleanUpdatedInputData(model, inputData);
|
|
478
559
|
|
|
479
|
-
|
|
480
|
-
|
|
560
|
+
/**
|
|
561
|
+
* Entries are identified by a common parent ID + Revision number.
|
|
562
|
+
*/
|
|
563
|
+
const {
|
|
564
|
+
id: uniqueId
|
|
565
|
+
} = (0, _utils.parseIdentifier)(sourceId);
|
|
566
|
+
const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
|
|
567
|
+
id: sourceId
|
|
568
|
+
});
|
|
569
|
+
const latestStorageEntry = await storageOperations.entries.getLatestRevisionByEntryId(model, {
|
|
570
|
+
id: uniqueId
|
|
571
|
+
});
|
|
572
|
+
if (!originalStorageEntry) {
|
|
573
|
+
throw new _handlerGraphql.NotFoundError(`Entry "${sourceId}" of model "${model.modelId}" was not found.`);
|
|
574
|
+
}
|
|
481
575
|
|
|
482
576
|
/**
|
|
483
|
-
*
|
|
484
|
-
*
|
|
485
|
-
* @internal
|
|
577
|
+
* We need to convert data from DB to its original form before using it further.
|
|
486
578
|
*/
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
579
|
+
const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
|
|
580
|
+
const initialValues = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, originalEntry.values), input);
|
|
581
|
+
await (0, _entryDataValidation.validateModelEntryData)({
|
|
582
|
+
context,
|
|
583
|
+
model,
|
|
584
|
+
data: initialValues,
|
|
585
|
+
entry: originalEntry
|
|
586
|
+
});
|
|
587
|
+
const values = await (0, _referenceFieldsMapping.referenceFieldsMapping)({
|
|
588
|
+
context,
|
|
589
|
+
model,
|
|
590
|
+
input: initialValues,
|
|
591
|
+
validateEntries: false
|
|
592
|
+
});
|
|
593
|
+
(0, _ownership.checkOwnership)(context, permission, originalEntry);
|
|
594
|
+
const identity = getIdentity();
|
|
595
|
+
const latestId = latestStorageEntry ? latestStorageEntry.id : sourceId;
|
|
596
|
+
const {
|
|
597
|
+
id,
|
|
598
|
+
version: nextVersion
|
|
599
|
+
} = increaseEntryIdVersion(latestId);
|
|
600
|
+
const entry = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, originalEntry), {}, {
|
|
601
|
+
id,
|
|
602
|
+
version: nextVersion,
|
|
603
|
+
savedOn: new Date().toISOString(),
|
|
604
|
+
createdOn: new Date().toISOString(),
|
|
605
|
+
createdBy: {
|
|
606
|
+
id: identity.id,
|
|
607
|
+
displayName: identity.displayName,
|
|
608
|
+
type: identity.type
|
|
609
|
+
},
|
|
610
|
+
modifiedBy: null,
|
|
611
|
+
locked: false,
|
|
612
|
+
publishedOn: undefined,
|
|
613
|
+
status: STATUS_DRAFT,
|
|
614
|
+
values
|
|
615
|
+
});
|
|
616
|
+
let storageEntry = null;
|
|
617
|
+
try {
|
|
618
|
+
await onEntryBeforeCreateRevision.publish({
|
|
619
|
+
input,
|
|
620
|
+
entry,
|
|
621
|
+
original: originalEntry,
|
|
622
|
+
model
|
|
495
623
|
});
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
* We always assign tenant and locale because we do not allow one model to have content through multiple tenants.
|
|
501
|
-
*/
|
|
502
|
-
|
|
503
|
-
const where = _objectSpread({}, initialWhere);
|
|
504
|
-
/**
|
|
505
|
-
* Possibly only get records which are owned by current user.
|
|
506
|
-
* Or if searching for the owner set that value - in the case that user can see other entries than their own.
|
|
507
|
-
*/
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
const ownedBy = permission.own ? getIdentity().id : where.ownedBy;
|
|
511
|
-
|
|
512
|
-
if (ownedBy !== undefined) {
|
|
513
|
-
where.ownedBy = ownedBy;
|
|
514
|
-
}
|
|
515
|
-
/**
|
|
516
|
-
* Where must contain either latest or published keys.
|
|
517
|
-
* We cannot list entries without one of those
|
|
518
|
-
*/
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
if (where.latest && where.published) {
|
|
522
|
-
throw new _error.default("Cannot list entries that are both published and latest.", "LIST_ENTRIES_ERROR", {
|
|
523
|
-
where
|
|
524
|
-
});
|
|
525
|
-
} else if (!where.latest && !where.published) {
|
|
526
|
-
throw new _error.default("Cannot list entries if we do not have latest or published defined.", "LIST_ENTRIES_ERROR", {
|
|
527
|
-
where
|
|
528
|
-
});
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
const fields = getSearchableFields({
|
|
532
|
-
model,
|
|
533
|
-
plugins: context.plugins,
|
|
534
|
-
fields: params.fields || []
|
|
624
|
+
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
625
|
+
const result = await storageOperations.entries.createRevisionFrom(model, {
|
|
626
|
+
entry,
|
|
627
|
+
storageEntry
|
|
535
628
|
});
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
where,
|
|
540
|
-
model
|
|
541
|
-
});
|
|
542
|
-
const {
|
|
543
|
-
hasMoreItems,
|
|
544
|
-
totalCount,
|
|
545
|
-
cursor,
|
|
546
|
-
items
|
|
547
|
-
} = await storageOperations.entries.list(model, _objectSpread(_objectSpread({}, params), {}, {
|
|
548
|
-
where,
|
|
549
|
-
fields
|
|
550
|
-
}));
|
|
551
|
-
const meta = {
|
|
552
|
-
hasMoreItems,
|
|
553
|
-
totalCount,
|
|
554
|
-
|
|
555
|
-
/**
|
|
556
|
-
* Cursor should be null if there are no more items to load.
|
|
557
|
-
* Just make sure of that, disregarding what is returned from the storageOperations.entries.list method.
|
|
558
|
-
*/
|
|
559
|
-
cursor: hasMoreItems ? cursor : null
|
|
560
|
-
};
|
|
561
|
-
return [items, meta];
|
|
562
|
-
} catch (ex) {
|
|
563
|
-
throw new _error.default("Error while fetching entries from storage.", "LIST_ENTRIES_ERROR", {
|
|
564
|
-
params,
|
|
565
|
-
error: ex,
|
|
566
|
-
model,
|
|
567
|
-
fields
|
|
568
|
-
});
|
|
569
|
-
}
|
|
570
|
-
},
|
|
571
|
-
listLatestEntries: async function (model, params) {
|
|
572
|
-
const where = (params === null || params === void 0 ? void 0 : params.where) || {};
|
|
573
|
-
return context.cms.listEntries(model, _objectSpread(_objectSpread({
|
|
574
|
-
sort: ["createdOn_DESC"]
|
|
575
|
-
}, params || {}), {}, {
|
|
576
|
-
where: _objectSpread(_objectSpread({}, where), {}, {
|
|
577
|
-
latest: true
|
|
578
|
-
})
|
|
579
|
-
}));
|
|
580
|
-
},
|
|
581
|
-
listPublishedEntries: async function (model, params) {
|
|
582
|
-
const where = (params === null || params === void 0 ? void 0 : params.where) || {};
|
|
583
|
-
return context.cms.listEntries(model, _objectSpread(_objectSpread({
|
|
584
|
-
sort: ["createdOn_DESC"]
|
|
585
|
-
}, params || {}), {}, {
|
|
586
|
-
where: _objectSpread(_objectSpread({}, where), {}, {
|
|
587
|
-
published: true
|
|
588
|
-
})
|
|
589
|
-
}));
|
|
590
|
-
},
|
|
591
|
-
createEntry: async (initialModel, inputData) => {
|
|
592
|
-
await checkEntryPermissions({
|
|
593
|
-
rwd: "w"
|
|
594
|
-
});
|
|
595
|
-
await (0, _access.checkModelAccess)(context, initialModel);
|
|
596
|
-
const model = (0, _valueKeyStorageConverter.attachCmsModelFieldConverters)({
|
|
597
|
-
model: initialModel,
|
|
598
|
-
plugins
|
|
599
|
-
});
|
|
600
|
-
/**
|
|
601
|
-
* Make sure we only work with fields that are defined in the model.
|
|
602
|
-
*/
|
|
603
|
-
|
|
604
|
-
const initialInput = mapAndCleanCreateInputData(model, inputData);
|
|
605
|
-
await (0, _entryDataValidation.validateModelEntryData)({
|
|
606
|
-
context,
|
|
629
|
+
await onEntryRevisionAfterCreate.publish({
|
|
630
|
+
input,
|
|
631
|
+
entry,
|
|
607
632
|
model,
|
|
608
|
-
|
|
633
|
+
original: originalEntry,
|
|
634
|
+
storageEntry: result
|
|
609
635
|
});
|
|
610
|
-
|
|
611
|
-
|
|
636
|
+
return result;
|
|
637
|
+
} catch (ex) {
|
|
638
|
+
await onEntryCreateRevisionError.publish({
|
|
639
|
+
entry,
|
|
640
|
+
original: originalEntry,
|
|
612
641
|
model,
|
|
613
|
-
input
|
|
614
|
-
|
|
642
|
+
input,
|
|
643
|
+
error: ex
|
|
615
644
|
});
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
};
|
|
623
|
-
const {
|
|
624
|
-
id,
|
|
625
|
-
entryId,
|
|
626
|
-
version
|
|
627
|
-
} = createEntryId(1);
|
|
628
|
-
const entry = {
|
|
629
|
-
webinyVersion: context.WEBINY_VERSION,
|
|
630
|
-
tenant: getTenant().id,
|
|
631
|
-
entryId,
|
|
632
|
-
id,
|
|
633
|
-
modelId: model.modelId,
|
|
634
|
-
locale: locale.code,
|
|
635
|
-
createdOn: new Date().toISOString(),
|
|
636
|
-
savedOn: new Date().toISOString(),
|
|
637
|
-
createdBy: owner,
|
|
638
|
-
ownedBy: owner,
|
|
639
|
-
version,
|
|
640
|
-
locked: false,
|
|
641
|
-
status: STATUS_DRAFT,
|
|
642
|
-
values: input
|
|
643
|
-
};
|
|
644
|
-
let storageEntry = null;
|
|
645
|
-
|
|
646
|
-
try {
|
|
647
|
-
await onBeforeEntryCreate.publish({
|
|
648
|
-
entry,
|
|
649
|
-
input,
|
|
650
|
-
model
|
|
651
|
-
});
|
|
652
|
-
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
653
|
-
const result = await storageOperations.entries.create(model, {
|
|
654
|
-
entry,
|
|
655
|
-
storageEntry
|
|
656
|
-
});
|
|
657
|
-
await onAfterEntryCreate.publish({
|
|
658
|
-
entry,
|
|
659
|
-
storageEntry: result,
|
|
660
|
-
model,
|
|
661
|
-
input
|
|
662
|
-
});
|
|
663
|
-
return result;
|
|
664
|
-
} catch (ex) {
|
|
665
|
-
throw new _error.default(ex.message || "Could not create content entry.", ex.code || "CREATE_ENTRY_ERROR", ex.data || {
|
|
666
|
-
error: ex,
|
|
667
|
-
input,
|
|
668
|
-
entry,
|
|
669
|
-
storageEntry
|
|
670
|
-
});
|
|
671
|
-
}
|
|
672
|
-
},
|
|
673
|
-
createEntryRevisionFrom: async (initialModel, sourceId, inputData) => {
|
|
674
|
-
const permission = await checkEntryPermissions({
|
|
675
|
-
rwd: "w"
|
|
676
|
-
});
|
|
677
|
-
await (0, _access.checkModelAccess)(context, initialModel);
|
|
678
|
-
const model = (0, _valueKeyStorageConverter.attachCmsModelFieldConverters)({
|
|
679
|
-
model: initialModel,
|
|
680
|
-
plugins
|
|
645
|
+
throw new _error.default(ex.message || "Could not create entry from existing one.", ex.code || "CREATE_FROM_REVISION_ERROR", {
|
|
646
|
+
error: ex,
|
|
647
|
+
entry,
|
|
648
|
+
storageEntry,
|
|
649
|
+
originalEntry,
|
|
650
|
+
originalStorageEntry
|
|
681
651
|
});
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
const updateEntry = async (model, id, inputData, metaInput) => {
|
|
655
|
+
const permission = await checkEntryPermissions({
|
|
656
|
+
rwd: "w"
|
|
657
|
+
});
|
|
658
|
+
await (0, _access.checkModelAccess)(context, model);
|
|
685
659
|
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
660
|
+
/**
|
|
661
|
+
* Make sure we only work with fields that are defined in the model.
|
|
662
|
+
*/
|
|
663
|
+
const input = mapAndCleanUpdatedInputData(model, inputData);
|
|
690
664
|
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
665
|
+
/**
|
|
666
|
+
* The entry we are going to update.
|
|
667
|
+
*/
|
|
668
|
+
const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
|
|
669
|
+
id
|
|
670
|
+
});
|
|
671
|
+
if (!originalStorageEntry) {
|
|
672
|
+
throw new _handlerGraphql.NotFoundError(`Entry "${id}" of model "${model.modelId}" was not found.`);
|
|
673
|
+
}
|
|
674
|
+
if (originalStorageEntry.locked) {
|
|
675
|
+
throw new _error.default(`Cannot update entry because it's locked.`, "CONTENT_ENTRY_UPDATE_ERROR");
|
|
676
|
+
}
|
|
677
|
+
const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
|
|
678
|
+
await (0, _entryDataValidation.validateModelEntryData)({
|
|
679
|
+
context,
|
|
680
|
+
model,
|
|
681
|
+
data: input,
|
|
682
|
+
entry: originalEntry
|
|
683
|
+
});
|
|
684
|
+
(0, _ownership.checkOwnership)(context, permission, originalEntry);
|
|
685
|
+
const initialValues = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, originalEntry.values), input);
|
|
686
|
+
const values = await (0, _referenceFieldsMapping.referenceFieldsMapping)({
|
|
687
|
+
context,
|
|
688
|
+
model,
|
|
689
|
+
input: initialValues,
|
|
690
|
+
validateEntries: false
|
|
691
|
+
});
|
|
692
|
+
/**
|
|
693
|
+
* If users wants to remove a key from meta values, they need to send meta key with the null value.
|
|
694
|
+
*/
|
|
695
|
+
const meta = createEntryMeta(metaInput, originalEntry.meta);
|
|
696
|
+
/**
|
|
697
|
+
* We always send the full entry to the hooks and storage operations update.
|
|
698
|
+
*/
|
|
699
|
+
const entry = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, originalEntry), {}, {
|
|
700
|
+
savedOn: new Date().toISOString(),
|
|
701
|
+
modifiedBy: getCreatedBy(),
|
|
702
|
+
values,
|
|
703
|
+
meta,
|
|
704
|
+
status: transformEntryStatus(originalEntry.status)
|
|
705
|
+
});
|
|
706
|
+
let storageEntry = null;
|
|
707
|
+
try {
|
|
708
|
+
await onEntryBeforeUpdate.publish({
|
|
709
|
+
entry,
|
|
710
|
+
model,
|
|
711
|
+
input,
|
|
712
|
+
original: originalEntry
|
|
696
713
|
});
|
|
697
|
-
|
|
698
|
-
|
|
714
|
+
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
715
|
+
const result = await storageOperations.entries.update(model, {
|
|
716
|
+
entry,
|
|
717
|
+
storageEntry
|
|
699
718
|
});
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
}
|
|
704
|
-
/**
|
|
705
|
-
* We need to convert data from DB to its original form before using it further.
|
|
706
|
-
*/
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
|
|
710
|
-
|
|
711
|
-
const initialValues = _objectSpread(_objectSpread({}, originalEntry.values), input);
|
|
712
|
-
|
|
713
|
-
await (0, _entryDataValidation.validateModelEntryData)({
|
|
714
|
-
context,
|
|
719
|
+
await onEntryAfterUpdate.publish({
|
|
720
|
+
entry,
|
|
721
|
+
storageEntry: result,
|
|
715
722
|
model,
|
|
716
|
-
|
|
717
|
-
|
|
723
|
+
input,
|
|
724
|
+
original: originalEntry
|
|
718
725
|
});
|
|
719
|
-
|
|
720
|
-
|
|
726
|
+
return result;
|
|
727
|
+
} catch (ex) {
|
|
728
|
+
await onEntryUpdateError.publish({
|
|
729
|
+
entry,
|
|
721
730
|
model,
|
|
722
|
-
input
|
|
723
|
-
|
|
731
|
+
input,
|
|
732
|
+
error: ex
|
|
724
733
|
});
|
|
725
|
-
(
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
|
|
734
|
+
throw new _error.default(ex.message || "Could not update existing entry.", ex.code || "UPDATE_ERROR", {
|
|
735
|
+
error: ex,
|
|
736
|
+
entry,
|
|
737
|
+
storageEntry,
|
|
738
|
+
originalEntry,
|
|
739
|
+
input
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
};
|
|
743
|
+
const republishEntry = async (model, id) => {
|
|
744
|
+
await checkEntryPermissions({
|
|
745
|
+
rwd: "w"
|
|
746
|
+
});
|
|
747
|
+
await (0, _access.checkModelAccess)(context, model);
|
|
748
|
+
/**
|
|
749
|
+
* Fetch the entry from the storage.
|
|
750
|
+
*/
|
|
751
|
+
const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
|
|
752
|
+
id
|
|
753
|
+
});
|
|
754
|
+
if (!originalStorageEntry) {
|
|
755
|
+
throw new _handlerGraphql.NotFoundError(`Entry "${id}" was not found!`);
|
|
756
|
+
}
|
|
757
|
+
const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
|
|
758
|
+
/**
|
|
759
|
+
* We can only process published entries.
|
|
760
|
+
*/
|
|
761
|
+
if (originalEntry.status !== "published") {
|
|
762
|
+
throw new _error.default("Entry with given ID is not published!", "NOT_PUBLISHED_ERROR", {
|
|
734
763
|
id,
|
|
735
|
-
|
|
736
|
-
savedOn: new Date().toISOString(),
|
|
737
|
-
createdOn: new Date().toISOString(),
|
|
738
|
-
createdBy: {
|
|
739
|
-
id: identity.id,
|
|
740
|
-
displayName: identity.displayName,
|
|
741
|
-
type: identity.type
|
|
742
|
-
},
|
|
743
|
-
locked: false,
|
|
744
|
-
publishedOn: undefined,
|
|
745
|
-
status: STATUS_DRAFT,
|
|
746
|
-
values
|
|
764
|
+
original: originalEntry
|
|
747
765
|
});
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
throw new _error.default(ex.message || "Could not create entry from existing one.", ex.code || "CREATE_FROM_REVISION_ERROR", {
|
|
773
|
-
error: ex,
|
|
774
|
-
entry,
|
|
775
|
-
storageEntry,
|
|
776
|
-
originalEntry,
|
|
777
|
-
originalStorageEntry
|
|
778
|
-
});
|
|
779
|
-
}
|
|
780
|
-
},
|
|
781
|
-
updateEntry: async (initialModel, id, inputData, metaInput) => {
|
|
782
|
-
const permission = await checkEntryPermissions({
|
|
783
|
-
rwd: "w"
|
|
766
|
+
}
|
|
767
|
+
const values = await (0, _referenceFieldsMapping.referenceFieldsMapping)({
|
|
768
|
+
context,
|
|
769
|
+
model,
|
|
770
|
+
input: originalEntry.values,
|
|
771
|
+
validateEntries: false
|
|
772
|
+
});
|
|
773
|
+
const entry = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, originalEntry), {}, {
|
|
774
|
+
savedOn: new Date().toISOString(),
|
|
775
|
+
webinyVersion: context.WEBINY_VERSION,
|
|
776
|
+
values
|
|
777
|
+
});
|
|
778
|
+
const storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
779
|
+
/**
|
|
780
|
+
* First we need to update existing entry.
|
|
781
|
+
*/
|
|
782
|
+
try {
|
|
783
|
+
await storageOperations.entries.update(model, {
|
|
784
|
+
entry,
|
|
785
|
+
storageEntry
|
|
786
|
+
});
|
|
787
|
+
} catch (ex) {
|
|
788
|
+
throw new _error.default("Could not update existing entry with new data while re-publishing.", "REPUBLISH_UPDATE_ERROR", {
|
|
789
|
+
entry
|
|
784
790
|
});
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* Then we move onto publishing it again.
|
|
794
|
+
*/
|
|
795
|
+
try {
|
|
796
|
+
await onEntryBeforeRepublish.publish({
|
|
797
|
+
entry,
|
|
798
|
+
model
|
|
789
799
|
});
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
const input = mapAndCleanUpdatedInputData(model, inputData);
|
|
795
|
-
/**
|
|
796
|
-
* The entry we are going to update.
|
|
797
|
-
*/
|
|
798
|
-
|
|
799
|
-
const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
|
|
800
|
-
id
|
|
800
|
+
const result = await storageOperations.entries.publish(model, {
|
|
801
|
+
entry,
|
|
802
|
+
storageEntry
|
|
801
803
|
});
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
throw new _handlerGraphql.NotFoundError(`Entry "${id}" of model "${model.modelId}" was not found.`);
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
if (originalStorageEntry.locked) {
|
|
808
|
-
throw new _error.default(`Cannot update entry because it's locked.`, "CONTENT_ENTRY_UPDATE_ERROR");
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
|
|
812
|
-
await (0, _entryDataValidation.validateModelEntryData)({
|
|
813
|
-
context,
|
|
804
|
+
await onEntryAfterRepublish.publish({
|
|
805
|
+
entry,
|
|
814
806
|
model,
|
|
815
|
-
|
|
816
|
-
entry: originalEntry
|
|
807
|
+
storageEntry
|
|
817
808
|
});
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
const values = await (0, _referenceFieldsMapping.referenceFieldsMapping)({
|
|
823
|
-
context,
|
|
809
|
+
return result;
|
|
810
|
+
} catch (ex) {
|
|
811
|
+
await onEntryRepublishError.publish({
|
|
812
|
+
entry,
|
|
824
813
|
model,
|
|
825
|
-
|
|
826
|
-
validateEntries: false
|
|
814
|
+
error: ex
|
|
827
815
|
});
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
*/
|
|
831
|
-
|
|
832
|
-
const meta = createEntryMeta(metaInput, originalEntry.meta);
|
|
833
|
-
/**
|
|
834
|
-
* We always send the full entry to the hooks and storage operations update.
|
|
835
|
-
*/
|
|
836
|
-
|
|
837
|
-
const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
|
|
838
|
-
savedOn: new Date().toISOString(),
|
|
839
|
-
values,
|
|
840
|
-
meta
|
|
816
|
+
throw new _error.default("Could not publish existing entry while re-publishing.", "REPUBLISH_PUBLISH_ERROR", {
|
|
817
|
+
entry
|
|
841
818
|
});
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
rwd: "w"
|
|
878
|
-
});
|
|
879
|
-
await (0, _access.checkModelAccess)(context, initialModel);
|
|
880
|
-
const model = (0, _valueKeyStorageConverter.attachCmsModelFieldConverters)({
|
|
881
|
-
model: initialModel,
|
|
882
|
-
plugins
|
|
883
|
-
});
|
|
884
|
-
/**
|
|
885
|
-
* Fetch the entry from the storage.
|
|
886
|
-
*/
|
|
887
|
-
|
|
888
|
-
const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
|
|
889
|
-
id
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
const deleteEntryRevision = async (model, revisionId) => {
|
|
822
|
+
const permission = await checkEntryPermissions({
|
|
823
|
+
rwd: "d"
|
|
824
|
+
});
|
|
825
|
+
await (0, _access.checkModelAccess)(context, model);
|
|
826
|
+
const {
|
|
827
|
+
id: entryId,
|
|
828
|
+
version
|
|
829
|
+
} = (0, _utils.parseIdentifier)(revisionId);
|
|
830
|
+
const storageEntryToDelete = await storageOperations.entries.getRevisionById(model, {
|
|
831
|
+
id: revisionId
|
|
832
|
+
});
|
|
833
|
+
const latestStorageEntry = await storageOperations.entries.getLatestRevisionByEntryId(model, {
|
|
834
|
+
id: entryId
|
|
835
|
+
});
|
|
836
|
+
const previousStorageEntry = await storageOperations.entries.getPreviousRevision(model, {
|
|
837
|
+
entryId,
|
|
838
|
+
version: version
|
|
839
|
+
});
|
|
840
|
+
if (!storageEntryToDelete) {
|
|
841
|
+
throw new _handlerGraphql.NotFoundError(`Entry "${revisionId}" was not found!`);
|
|
842
|
+
}
|
|
843
|
+
(0, _ownership.checkOwnership)(context, permission, storageEntryToDelete);
|
|
844
|
+
const latestEntryRevisionId = latestStorageEntry ? latestStorageEntry.id : null;
|
|
845
|
+
const entryToDelete = await (0, _entryStorage.entryFromStorageTransform)(context, model, storageEntryToDelete);
|
|
846
|
+
/**
|
|
847
|
+
* If targeted record is the latest entry record and there is no previous one, we need to run full delete with hooks.
|
|
848
|
+
* At this point deleteRevision hooks are not fired.
|
|
849
|
+
*/
|
|
850
|
+
if (entryToDelete.id === latestEntryRevisionId && !previousStorageEntry) {
|
|
851
|
+
return await deleteEntryHelper({
|
|
852
|
+
model,
|
|
853
|
+
entry: entryToDelete
|
|
890
854
|
});
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* If targeted record is latest entry revision, set the previous one as the new latest
|
|
858
|
+
*/
|
|
859
|
+
let entryToSetAsLatest = null;
|
|
860
|
+
let storageEntryToSetAsLatest = null;
|
|
861
|
+
if (entryToDelete.id === latestEntryRevisionId && previousStorageEntry) {
|
|
862
|
+
entryToSetAsLatest = await (0, _entryStorage.entryFromStorageTransform)(context, model, previousStorageEntry);
|
|
863
|
+
storageEntryToSetAsLatest = previousStorageEntry;
|
|
864
|
+
}
|
|
865
|
+
try {
|
|
866
|
+
await onEntryRevisionBeforeDelete.publish({
|
|
867
|
+
entry: entryToDelete,
|
|
868
|
+
model
|
|
869
|
+
});
|
|
870
|
+
await storageOperations.entries.deleteRevision(model, {
|
|
871
|
+
entry: entryToDelete,
|
|
872
|
+
storageEntry: storageEntryToDelete,
|
|
873
|
+
latestEntry: entryToSetAsLatest,
|
|
874
|
+
latestStorageEntry: storageEntryToSetAsLatest
|
|
875
|
+
});
|
|
876
|
+
await onEntryRevisionAfterDelete.publish({
|
|
877
|
+
entry: entryToDelete,
|
|
878
|
+
model
|
|
879
|
+
});
|
|
880
|
+
} catch (ex) {
|
|
881
|
+
await onEntryRevisionDeleteError.publish({
|
|
882
|
+
entry: entryToDelete,
|
|
910
883
|
model,
|
|
911
|
-
|
|
912
|
-
validateEntries: false
|
|
884
|
+
error: ex
|
|
913
885
|
});
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
886
|
+
throw new _error.default(ex.message, ex.code || "DELETE_REVISION_ERROR", {
|
|
887
|
+
error: ex,
|
|
888
|
+
entry: entryToDelete,
|
|
889
|
+
storageEntry: storageEntryToDelete,
|
|
890
|
+
latestEntry: entryToSetAsLatest,
|
|
891
|
+
latestStorageEntry: storageEntryToSetAsLatest
|
|
919
892
|
});
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
893
|
+
}
|
|
894
|
+
};
|
|
895
|
+
const deleteEntry = async (model, entryId) => {
|
|
896
|
+
const permission = await checkEntryPermissions({
|
|
897
|
+
rwd: "d"
|
|
898
|
+
});
|
|
899
|
+
await (0, _access.checkModelAccess)(context, model);
|
|
900
|
+
const storageEntry = await storageOperations.entries.getLatestRevisionByEntryId(model, {
|
|
901
|
+
id: entryId
|
|
902
|
+
});
|
|
903
|
+
if (!storageEntry) {
|
|
904
|
+
throw new _handlerGraphql.NotFoundError(`Entry "${entryId}" was not found!`);
|
|
905
|
+
}
|
|
906
|
+
(0, _ownership.checkOwnership)(context, permission, storageEntry);
|
|
907
|
+
const entry = await (0, _entryStorage.entryFromStorageTransform)(context, model, storageEntry);
|
|
908
|
+
return await deleteEntryHelper({
|
|
909
|
+
model,
|
|
910
|
+
entry
|
|
911
|
+
});
|
|
912
|
+
};
|
|
913
|
+
const publishEntry = async (model, id) => {
|
|
914
|
+
const permission = await checkEntryPermissions({
|
|
915
|
+
pw: "p"
|
|
916
|
+
});
|
|
917
|
+
await (0, _access.checkModelAccess)(context, model);
|
|
918
|
+
const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
|
|
919
|
+
id
|
|
920
|
+
});
|
|
921
|
+
if (!originalStorageEntry) {
|
|
922
|
+
throw new _handlerGraphql.NotFoundError(`Entry "${id}" in the model "${model.modelId}" was not found.`);
|
|
923
|
+
}
|
|
924
|
+
(0, _ownership.checkOwnership)(context, permission, originalStorageEntry);
|
|
925
|
+
const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
|
|
926
|
+
const currentDate = new Date().toISOString();
|
|
927
|
+
const entry = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, originalEntry), {}, {
|
|
928
|
+
status: STATUS_PUBLISHED,
|
|
929
|
+
locked: true,
|
|
930
|
+
savedOn: currentDate,
|
|
931
|
+
publishedOn: currentDate
|
|
932
|
+
});
|
|
933
|
+
let storageEntry = null;
|
|
934
|
+
try {
|
|
935
|
+
await onEntryBeforePublish.publish({
|
|
936
|
+
entry,
|
|
937
|
+
model
|
|
955
938
|
});
|
|
956
|
-
await (0,
|
|
957
|
-
const
|
|
958
|
-
|
|
959
|
-
|
|
939
|
+
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
940
|
+
const result = await storageOperations.entries.publish(model, {
|
|
941
|
+
entry,
|
|
942
|
+
storageEntry
|
|
960
943
|
});
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
const storageEntryToDelete = await storageOperations.entries.getRevisionById(model, {
|
|
966
|
-
id: revisionId
|
|
944
|
+
await onEntryAfterPublish.publish({
|
|
945
|
+
entry,
|
|
946
|
+
storageEntry: result,
|
|
947
|
+
model
|
|
967
948
|
});
|
|
968
|
-
|
|
969
|
-
|
|
949
|
+
return result;
|
|
950
|
+
} catch (ex) {
|
|
951
|
+
await onEntryPublishError.publish({
|
|
952
|
+
entry,
|
|
953
|
+
model,
|
|
954
|
+
error: ex
|
|
970
955
|
});
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
956
|
+
throw new _error.default(ex.message || "Could not publish entry.", ex.code || "PUBLISH_ERROR", {
|
|
957
|
+
error: ex,
|
|
958
|
+
entry,
|
|
959
|
+
storageEntry,
|
|
960
|
+
originalEntry,
|
|
961
|
+
originalStorageEntry
|
|
974
962
|
});
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
try {
|
|
1008
|
-
await onBeforeEntryDeleteRevision.publish({
|
|
1009
|
-
entry: entryToDelete,
|
|
1010
|
-
model
|
|
1011
|
-
});
|
|
1012
|
-
await storageOperations.entries.deleteRevision(model, {
|
|
1013
|
-
entry: entryToDelete,
|
|
1014
|
-
storageEntry: storageEntryToDelete,
|
|
1015
|
-
latestEntry: entryToSetAsLatest,
|
|
1016
|
-
latestStorageEntry: storageEntryToSetAsLatest
|
|
1017
|
-
});
|
|
1018
|
-
await onAfterEntryDeleteRevision.publish({
|
|
1019
|
-
entry: entryToDelete,
|
|
1020
|
-
model
|
|
1021
|
-
});
|
|
1022
|
-
} catch (ex) {
|
|
1023
|
-
throw new _error.default(ex.message, ex.code || "DELETE_REVISION_ERROR", {
|
|
1024
|
-
error: ex,
|
|
1025
|
-
entry: entryToDelete,
|
|
1026
|
-
storageEntry: storageEntryToDelete,
|
|
1027
|
-
latestEntry: entryToSetAsLatest,
|
|
1028
|
-
latestStorageEntry: storageEntryToSetAsLatest
|
|
1029
|
-
});
|
|
1030
|
-
}
|
|
1031
|
-
},
|
|
1032
|
-
deleteEntry: async (initialModel, entryId) => {
|
|
1033
|
-
const permission = await checkEntryPermissions({
|
|
1034
|
-
rwd: "d"
|
|
963
|
+
}
|
|
964
|
+
};
|
|
965
|
+
const unpublishEntry = async (model, id) => {
|
|
966
|
+
const permission = await checkEntryPermissions({
|
|
967
|
+
pw: "u"
|
|
968
|
+
});
|
|
969
|
+
const {
|
|
970
|
+
id: entryId
|
|
971
|
+
} = (0, _utils.parseIdentifier)(id);
|
|
972
|
+
const originalStorageEntry = await storageOperations.entries.getPublishedRevisionByEntryId(model, {
|
|
973
|
+
id: entryId
|
|
974
|
+
});
|
|
975
|
+
if (!originalStorageEntry) {
|
|
976
|
+
throw new _handlerGraphql.NotFoundError(`Entry "${id}" of model "${model.modelId}" was not found.`);
|
|
977
|
+
}
|
|
978
|
+
if (originalStorageEntry.id !== id) {
|
|
979
|
+
throw new _error.default(`Entry is not published.`, "UNPUBLISH_ERROR", {
|
|
980
|
+
entry: originalStorageEntry
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
(0, _ownership.checkOwnership)(context, permission, originalStorageEntry);
|
|
984
|
+
const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
|
|
985
|
+
const entry = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, originalEntry), {}, {
|
|
986
|
+
status: STATUS_UNPUBLISHED
|
|
987
|
+
});
|
|
988
|
+
let storageEntry = null;
|
|
989
|
+
try {
|
|
990
|
+
await onEntryBeforeUnpublish.publish({
|
|
991
|
+
entry,
|
|
992
|
+
model
|
|
1035
993
|
});
|
|
1036
|
-
await (0,
|
|
1037
|
-
const
|
|
1038
|
-
|
|
1039
|
-
|
|
994
|
+
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
995
|
+
const result = await storageOperations.entries.unpublish(model, {
|
|
996
|
+
entry,
|
|
997
|
+
storageEntry
|
|
1040
998
|
});
|
|
1041
|
-
|
|
1042
|
-
|
|
999
|
+
await onEntryAfterUnpublish.publish({
|
|
1000
|
+
entry,
|
|
1001
|
+
storageEntry: result,
|
|
1002
|
+
model
|
|
1043
1003
|
});
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
(0, _ownership.checkOwnership)(context, permission, storageEntry);
|
|
1050
|
-
const entry = await (0, _entryStorage.entryFromStorageTransform)(context, model, storageEntry);
|
|
1051
|
-
return await deleteEntry({
|
|
1004
|
+
return result;
|
|
1005
|
+
} catch (ex) {
|
|
1006
|
+
await onEntryUnpublishError.publish({
|
|
1007
|
+
entry,
|
|
1052
1008
|
model,
|
|
1053
|
-
|
|
1009
|
+
error: ex
|
|
1054
1010
|
});
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1011
|
+
throw new _error.default(ex.message || "Could not unpublish entry.", ex.code || "UNPUBLISH_ERROR", {
|
|
1012
|
+
originalEntry,
|
|
1013
|
+
originalStorageEntry,
|
|
1014
|
+
entry,
|
|
1015
|
+
storageEntry
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
};
|
|
1019
|
+
const getUniqueFieldValues = async (model, params) => {
|
|
1020
|
+
const permission = await checkEntryPermissions({
|
|
1021
|
+
rwd: "r"
|
|
1022
|
+
});
|
|
1023
|
+
await (0, _access.checkModelAccess)(context, model);
|
|
1024
|
+
const {
|
|
1025
|
+
where: initialWhere,
|
|
1026
|
+
fieldId
|
|
1027
|
+
} = params;
|
|
1028
|
+
const where = (0, _objectSpread2.default)({}, initialWhere);
|
|
1029
|
+
/**
|
|
1030
|
+
* Possibly only get records which are owned by current user.
|
|
1031
|
+
* Or if searching for the owner set that value - in the case that user can see other entries than their own.
|
|
1032
|
+
*/
|
|
1033
|
+
const ownedBy = permission.own ? getIdentity().id : where.ownedBy;
|
|
1034
|
+
if (ownedBy !== undefined) {
|
|
1035
|
+
where.ownedBy = ownedBy;
|
|
1036
|
+
}
|
|
1037
|
+
/**
|
|
1038
|
+
* Where must contain either latest or published keys.
|
|
1039
|
+
* We cannot list entries without one of those
|
|
1040
|
+
*/
|
|
1041
|
+
if (where.latest && where.published) {
|
|
1042
|
+
throw new _error.default("Cannot list entries that are both published and latest.", "LIST_ENTRIES_ERROR", {
|
|
1043
|
+
where
|
|
1059
1044
|
});
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
plugins
|
|
1045
|
+
} else if (!where.latest && !where.published) {
|
|
1046
|
+
throw new _error.default("Cannot list entries if we do not have latest or published defined.", "LIST_ENTRIES_ERROR", {
|
|
1047
|
+
where
|
|
1064
1048
|
});
|
|
1065
|
-
|
|
1066
|
-
|
|
1049
|
+
}
|
|
1050
|
+
/**
|
|
1051
|
+
* We need to verify that the field in question is searchable.
|
|
1052
|
+
*/
|
|
1053
|
+
const fields = (0, _searchableFields.getSearchableFields)({
|
|
1054
|
+
fields: model.fields,
|
|
1055
|
+
plugins: context.plugins,
|
|
1056
|
+
input: []
|
|
1057
|
+
});
|
|
1058
|
+
if (fields.includes(fieldId) === false) {
|
|
1059
|
+
throw new _error.default("Cannot list unique entry field values if the field is not searchable.", "LIST_UNIQUE_ENTRY_VALUES_ERROR", {
|
|
1060
|
+
fieldId
|
|
1067
1061
|
});
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1062
|
+
}
|
|
1063
|
+
try {
|
|
1064
|
+
return await storageOperations.entries.getUniqueFieldValues(model, {
|
|
1065
|
+
where,
|
|
1066
|
+
fieldId
|
|
1067
|
+
});
|
|
1068
|
+
} catch (ex) {
|
|
1069
|
+
throw new _error.default("Error while fetching unique entry values from storage.", "LIST_UNIQUE_ENTRY_VALUES_ERROR", {
|
|
1070
|
+
error: {
|
|
1071
|
+
message: ex.message,
|
|
1072
|
+
code: ex.code,
|
|
1073
|
+
data: ex.data
|
|
1074
|
+
},
|
|
1075
|
+
model,
|
|
1076
|
+
where,
|
|
1077
|
+
fieldId
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
};
|
|
1081
|
+
return {
|
|
1082
|
+
/**
|
|
1083
|
+
* Deprecated - will be removed in 5.35.0
|
|
1084
|
+
*/
|
|
1085
|
+
onBeforeEntryCreate: onEntryBeforeCreate,
|
|
1086
|
+
onAfterEntryCreate: onEntryAfterCreate,
|
|
1087
|
+
onBeforeEntryCreateRevision: onEntryBeforeCreateRevision,
|
|
1088
|
+
onAfterEntryCreateRevision: onEntryRevisionAfterCreate,
|
|
1089
|
+
onBeforeEntryUpdate: onEntryBeforeUpdate,
|
|
1090
|
+
onAfterEntryUpdate: onEntryAfterUpdate,
|
|
1091
|
+
onBeforeEntryDelete: onEntryBeforeDelete,
|
|
1092
|
+
onAfterEntryDelete: onEntryAfterDelete,
|
|
1093
|
+
onBeforeEntryDeleteRevision: onEntryRevisionBeforeDelete,
|
|
1094
|
+
onAfterEntryDeleteRevision: onEntryRevisionAfterDelete,
|
|
1095
|
+
onBeforeEntryPublish: onEntryBeforePublish,
|
|
1096
|
+
onAfterEntryPublish: onEntryAfterPublish,
|
|
1097
|
+
onBeforeEntryUnpublish: onEntryBeforeUnpublish,
|
|
1098
|
+
onAfterEntryUnpublish: onEntryAfterUnpublish,
|
|
1099
|
+
onBeforeEntryGet: onEntryBeforeGet,
|
|
1100
|
+
onBeforeEntryList: onEntryBeforeList,
|
|
1101
|
+
/**
|
|
1102
|
+
* Released in 5.34.0
|
|
1103
|
+
*
|
|
1104
|
+
* Create
|
|
1105
|
+
*/
|
|
1106
|
+
onEntryBeforeCreate,
|
|
1107
|
+
onEntryAfterCreate,
|
|
1108
|
+
onEntryCreateError,
|
|
1109
|
+
/**
|
|
1110
|
+
* Create revision
|
|
1111
|
+
*/
|
|
1112
|
+
onEntryRevisionBeforeCreate: onEntryBeforeCreateRevision,
|
|
1113
|
+
onEntryRevisionAfterCreate,
|
|
1114
|
+
onEntryRevisionCreateError: onEntryCreateRevisionError,
|
|
1115
|
+
/**
|
|
1116
|
+
* Update
|
|
1117
|
+
*/
|
|
1118
|
+
onEntryBeforeUpdate,
|
|
1119
|
+
onEntryAfterUpdate,
|
|
1120
|
+
onEntryUpdateError,
|
|
1121
|
+
/**
|
|
1122
|
+
* Delete whole entry
|
|
1123
|
+
*/
|
|
1124
|
+
onEntryBeforeDelete,
|
|
1125
|
+
onEntryAfterDelete,
|
|
1126
|
+
onEntryDeleteError,
|
|
1127
|
+
/**
|
|
1128
|
+
* Delete entry revision
|
|
1129
|
+
*/
|
|
1130
|
+
onEntryRevisionBeforeDelete,
|
|
1131
|
+
onEntryRevisionAfterDelete,
|
|
1132
|
+
onEntryRevisionDeleteError,
|
|
1133
|
+
/**
|
|
1134
|
+
* Publish
|
|
1135
|
+
*/
|
|
1136
|
+
onEntryBeforePublish,
|
|
1137
|
+
onEntryAfterPublish,
|
|
1138
|
+
onEntryPublishError,
|
|
1139
|
+
/**
|
|
1140
|
+
* Republish
|
|
1141
|
+
*/
|
|
1142
|
+
onEntryBeforeRepublish,
|
|
1143
|
+
onEntryAfterRepublish,
|
|
1144
|
+
onEntryRepublishError,
|
|
1145
|
+
/**
|
|
1146
|
+
* Unpublish
|
|
1147
|
+
*/
|
|
1148
|
+
onEntryBeforeUnpublish,
|
|
1149
|
+
onEntryAfterUnpublish,
|
|
1150
|
+
onEntryUnpublishError,
|
|
1151
|
+
onEntryBeforeGet,
|
|
1152
|
+
onEntryBeforeList,
|
|
1153
|
+
/**
|
|
1154
|
+
* Get entries by exact revision IDs from the database.
|
|
1155
|
+
*/
|
|
1156
|
+
getEntriesByIds,
|
|
1157
|
+
/**
|
|
1158
|
+
* Get a single entry by revision ID from the database.
|
|
1159
|
+
*/
|
|
1160
|
+
async getEntryById(model, id) {
|
|
1161
|
+
return context.benchmark.measure("headlessCms.crud.entries.getEntryById", async () => {
|
|
1162
|
+
return getEntryById(model, id);
|
|
1082
1163
|
});
|
|
1083
|
-
|
|
1084
|
-
let storageEntry = null;
|
|
1085
|
-
|
|
1086
|
-
try {
|
|
1087
|
-
await onBeforeEntryPublish.publish({
|
|
1088
|
-
entry,
|
|
1089
|
-
model
|
|
1090
|
-
});
|
|
1091
|
-
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
1092
|
-
const result = await storageOperations.entries.publish(model, {
|
|
1093
|
-
entry,
|
|
1094
|
-
storageEntry
|
|
1095
|
-
});
|
|
1096
|
-
await onAfterEntryPublish.publish({
|
|
1097
|
-
entry,
|
|
1098
|
-
storageEntry: result,
|
|
1099
|
-
model
|
|
1100
|
-
});
|
|
1101
|
-
return result;
|
|
1102
|
-
} catch (ex) {
|
|
1103
|
-
throw new _error.default(ex.message || "Could not publish entry.", ex.code || "PUBLISH_ERROR", {
|
|
1104
|
-
error: ex,
|
|
1105
|
-
entry,
|
|
1106
|
-
storageEntry,
|
|
1107
|
-
originalEntry,
|
|
1108
|
-
originalStorageEntry
|
|
1109
|
-
});
|
|
1110
|
-
}
|
|
1111
1164
|
},
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1165
|
+
/**
|
|
1166
|
+
* Get published revisions by entry IDs.
|
|
1167
|
+
*/
|
|
1168
|
+
async getPublishedEntriesByIds(model, ids) {
|
|
1169
|
+
return context.benchmark.measure("headlessCms.crud.entries.getPublishedEntriesByIds", async () => {
|
|
1170
|
+
return getPublishedEntriesByIds(model, ids);
|
|
1115
1171
|
});
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1172
|
+
},
|
|
1173
|
+
/**
|
|
1174
|
+
* Get the latest revisions by entry IDs.
|
|
1175
|
+
*/
|
|
1176
|
+
async getLatestEntriesByIds(model, ids) {
|
|
1177
|
+
return context.benchmark.measure("headlessCms.crud.entries.getLatestEntriesByIds", async () => {
|
|
1178
|
+
return getLatestEntriesByIds(model, ids);
|
|
1119
1179
|
});
|
|
1120
|
-
|
|
1121
|
-
|
|
1180
|
+
},
|
|
1181
|
+
async getEntryRevisions(model, entryId) {
|
|
1182
|
+
return context.benchmark.measure("headlessCms.crud.entries.getEntryRevisions", async () => {
|
|
1183
|
+
return getEntryRevisions(model, entryId);
|
|
1122
1184
|
});
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
}
|
|
1133
|
-
|
|
1134
|
-
const identity = context.security.getIdentity();
|
|
1135
|
-
|
|
1136
|
-
if (originalEntry.ownedBy.id === identity.id) {
|
|
1137
|
-
throw new _error.default("You cannot request changes on your own entry.", "CANNOT_REQUEST_CHANGES_ON_OWN_ENTRY");
|
|
1138
|
-
}
|
|
1139
|
-
|
|
1140
|
-
(0, _ownership.checkOwnership)(context, permission, originalEntry);
|
|
1141
|
-
|
|
1142
|
-
const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
|
|
1143
|
-
status: STATUS_CHANGES_REQUESTED
|
|
1185
|
+
},
|
|
1186
|
+
/**
|
|
1187
|
+
* TODO determine if this method is required at all.
|
|
1188
|
+
*
|
|
1189
|
+
* @internal
|
|
1190
|
+
*/
|
|
1191
|
+
async getEntry(model, params) {
|
|
1192
|
+
return context.benchmark.measure("headlessCms.crud.entries.getEntry", async () => {
|
|
1193
|
+
return getEntry(model, params);
|
|
1144
1194
|
});
|
|
1145
|
-
|
|
1146
|
-
let storageEntry = null;
|
|
1147
|
-
|
|
1148
|
-
try {
|
|
1149
|
-
await onBeforeEntryRequestChanges.publish({
|
|
1150
|
-
entry,
|
|
1151
|
-
model
|
|
1152
|
-
});
|
|
1153
|
-
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
1154
|
-
const result = await storageOperations.entries.requestChanges(model, {
|
|
1155
|
-
entry,
|
|
1156
|
-
storageEntry
|
|
1157
|
-
});
|
|
1158
|
-
await onAfterEntryRequestChanges.publish({
|
|
1159
|
-
entry,
|
|
1160
|
-
storageEntry: result,
|
|
1161
|
-
model
|
|
1162
|
-
});
|
|
1163
|
-
return result;
|
|
1164
|
-
} catch (ex) {
|
|
1165
|
-
throw new _error.default(ex.message || "Could not request changes for the entry.", ex.code || "REQUEST_CHANGES_ERROR", {
|
|
1166
|
-
entry,
|
|
1167
|
-
originalEntry
|
|
1168
|
-
});
|
|
1169
|
-
}
|
|
1170
1195
|
},
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1196
|
+
/**
|
|
1197
|
+
* @description Should not be used directly. Internal use only!
|
|
1198
|
+
*
|
|
1199
|
+
* @internal
|
|
1200
|
+
*/
|
|
1201
|
+
async listEntries(model, params) {
|
|
1202
|
+
return context.benchmark.measure("headlessCms.crud.entries.listEntries", async () => {
|
|
1203
|
+
return listEntries(model, params);
|
|
1174
1204
|
});
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1205
|
+
},
|
|
1206
|
+
async listLatestEntries(model, params) {
|
|
1207
|
+
const where = (params === null || params === void 0 ? void 0 : params.where) || {};
|
|
1208
|
+
return this.listEntries(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({
|
|
1209
|
+
sort: ["createdOn_DESC"]
|
|
1210
|
+
}, params || {}), {}, {
|
|
1211
|
+
where: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, where), {}, {
|
|
1212
|
+
latest: true
|
|
1213
|
+
})
|
|
1214
|
+
}));
|
|
1215
|
+
},
|
|
1216
|
+
async listPublishedEntries(model, params) {
|
|
1217
|
+
const where = (params === null || params === void 0 ? void 0 : params.where) || {};
|
|
1218
|
+
return this.listEntries(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({
|
|
1219
|
+
sort: ["createdOn_DESC"]
|
|
1220
|
+
}, params || {}), {}, {
|
|
1221
|
+
where: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, where), {}, {
|
|
1222
|
+
published: true
|
|
1223
|
+
})
|
|
1224
|
+
}));
|
|
1225
|
+
},
|
|
1226
|
+
async createEntry(model, input) {
|
|
1227
|
+
return context.benchmark.measure("headlessCms.crud.entries.createEntry", async () => {
|
|
1228
|
+
return createEntry(model, input);
|
|
1181
1229
|
});
|
|
1182
|
-
|
|
1183
|
-
|
|
1230
|
+
},
|
|
1231
|
+
async createEntryRevisionFrom(model, sourceId, input) {
|
|
1232
|
+
return context.benchmark.measure("headlessCms.crud.entries.createEntryRevisionFrom", async () => {
|
|
1233
|
+
return createEntryRevisionFrom(model, sourceId, input);
|
|
1184
1234
|
});
|
|
1185
|
-
|
|
1186
|
-
|
|
1235
|
+
},
|
|
1236
|
+
async updateEntry(model, id, input, meta) {
|
|
1237
|
+
return context.benchmark.measure("headlessCms.crud.entries.updateEntry", async () => {
|
|
1238
|
+
return updateEntry(model, id, input, meta);
|
|
1187
1239
|
});
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
const allowedStatuses = [STATUS_DRAFT, STATUS_CHANGES_REQUESTED];
|
|
1197
|
-
|
|
1198
|
-
if (!allowedStatuses.includes(originalEntry.status)) {
|
|
1199
|
-
throw new _error.default("Cannot request review - entry is not a draft nor was a change request issued.", "REQUEST_REVIEW_ERROR", {
|
|
1200
|
-
entry: originalEntry
|
|
1201
|
-
});
|
|
1202
|
-
}
|
|
1203
|
-
|
|
1204
|
-
(0, _ownership.checkOwnership)(context, permission, originalEntry);
|
|
1205
|
-
|
|
1206
|
-
const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
|
|
1207
|
-
status: STATUS_REVIEW_REQUESTED
|
|
1240
|
+
},
|
|
1241
|
+
/**
|
|
1242
|
+
* Method used internally. Not documented and should not be used in users systems.
|
|
1243
|
+
* @internal
|
|
1244
|
+
*/
|
|
1245
|
+
async republishEntry(model, id) {
|
|
1246
|
+
return context.benchmark.measure("headlessCms.crud.entries.republishEntry", async () => {
|
|
1247
|
+
return republishEntry(model, id);
|
|
1208
1248
|
});
|
|
1209
|
-
|
|
1210
|
-
let storageEntry = null;
|
|
1211
|
-
|
|
1212
|
-
try {
|
|
1213
|
-
await onBeforeEntryRequestReview.publish({
|
|
1214
|
-
entry,
|
|
1215
|
-
model
|
|
1216
|
-
});
|
|
1217
|
-
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
1218
|
-
const result = await storageOperations.entries.requestReview(model, {
|
|
1219
|
-
entry,
|
|
1220
|
-
storageEntry
|
|
1221
|
-
});
|
|
1222
|
-
await onAfterEntryRequestReview.publish({
|
|
1223
|
-
entry,
|
|
1224
|
-
storageEntry: result,
|
|
1225
|
-
model
|
|
1226
|
-
});
|
|
1227
|
-
return result;
|
|
1228
|
-
} catch (ex) {
|
|
1229
|
-
throw new _error.default(ex.message || "Could not request review on the entry.", ex.code || "REQUEST_REVIEW_ERROR", {
|
|
1230
|
-
originalEntry,
|
|
1231
|
-
entry
|
|
1232
|
-
});
|
|
1233
|
-
}
|
|
1234
1249
|
},
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1250
|
+
async deleteEntryRevision(model, id) {
|
|
1251
|
+
return context.benchmark.measure("headlessCms.crud.entries.deleteEntryRevision", async () => {
|
|
1252
|
+
return deleteEntryRevision(model, id);
|
|
1238
1253
|
});
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1254
|
+
},
|
|
1255
|
+
async deleteEntry(model, entryId) {
|
|
1256
|
+
return context.benchmark.measure("headlessCms.crud.entries.deleteEntry", async () => {
|
|
1257
|
+
return deleteEntry(model, entryId);
|
|
1242
1258
|
});
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
id: entryId
|
|
1259
|
+
},
|
|
1260
|
+
async publishEntry(model, id) {
|
|
1261
|
+
return context.benchmark.measure("headlessCms.crud.entries.publishEntry", async () => {
|
|
1262
|
+
return publishEntry(model, id);
|
|
1248
1263
|
});
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
}
|
|
1259
|
-
|
|
1260
|
-
(0, _ownership.checkOwnership)(context, permission, originalStorageEntry);
|
|
1261
|
-
const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
|
|
1262
|
-
|
|
1263
|
-
const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
|
|
1264
|
-
status: STATUS_UNPUBLISHED
|
|
1264
|
+
},
|
|
1265
|
+
async unpublishEntry(model, id) {
|
|
1266
|
+
return context.benchmark.measure("headlessCms.crud.entries.unpublishEntry", async () => {
|
|
1267
|
+
return unpublishEntry(model, id);
|
|
1268
|
+
});
|
|
1269
|
+
},
|
|
1270
|
+
async getUniqueFieldValues(model, params) {
|
|
1271
|
+
return context.benchmark.measure("headlessCms.crud.entries.getUniqueFieldValues", async () => {
|
|
1272
|
+
return getUniqueFieldValues(model, params);
|
|
1265
1273
|
});
|
|
1266
|
-
|
|
1267
|
-
let storageEntry = null;
|
|
1268
|
-
|
|
1269
|
-
try {
|
|
1270
|
-
await onBeforeEntryUnpublish.publish({
|
|
1271
|
-
entry,
|
|
1272
|
-
model
|
|
1273
|
-
});
|
|
1274
|
-
storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
|
|
1275
|
-
const result = await storageOperations.entries.unpublish(model, {
|
|
1276
|
-
entry,
|
|
1277
|
-
storageEntry
|
|
1278
|
-
});
|
|
1279
|
-
await onAfterEntryUnpublish.publish({
|
|
1280
|
-
entry,
|
|
1281
|
-
storageEntry: result,
|
|
1282
|
-
model
|
|
1283
|
-
});
|
|
1284
|
-
return result;
|
|
1285
|
-
} catch (ex) {
|
|
1286
|
-
throw new _error.default(ex.message || "Could not unpublish entry.", ex.code || "UNPUBLISH_ERROR", {
|
|
1287
|
-
originalEntry,
|
|
1288
|
-
originalStorageEntry,
|
|
1289
|
-
entry,
|
|
1290
|
-
storageEntry
|
|
1291
|
-
});
|
|
1292
|
-
}
|
|
1293
1274
|
}
|
|
1294
1275
|
};
|
|
1295
1276
|
};
|
|
1296
|
-
|
|
1297
1277
|
exports.createContentEntryCrud = createContentEntryCrud;
|