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