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