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