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