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