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