@webiny/api-headless-cms 0.0.0-unstable.1e66d121db → 0.0.0-unstable.2696f9d9e8
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 +32 -0
- package/constants.js +57 -0
- package/constants.js.map +1 -0
- package/context.d.ts +5 -2
- package/context.js +100 -25
- package/context.js.map +1 -1
- package/crud/contentEntry/afterDelete.js +2 -5
- package/crud/contentEntry/afterDelete.js.map +1 -1
- package/crud/contentEntry/beforeCreate.js +2 -3
- package/crud/contentEntry/beforeCreate.js.map +1 -1
- package/crud/contentEntry/beforeUpdate.js +2 -3
- package/crud/contentEntry/beforeUpdate.js.map +1 -1
- package/crud/contentEntry/entryDataFactories/createEntryData.d.ts +20 -0
- package/crud/contentEntry/entryDataFactories/createEntryData.js +228 -0
- package/crud/contentEntry/entryDataFactories/createEntryData.js.map +1 -0
- package/crud/contentEntry/entryDataFactories/createEntryRevisionFromData.d.ts +21 -0
- package/crud/contentEntry/entryDataFactories/createEntryRevisionFromData.js +114 -0
- package/crud/contentEntry/entryDataFactories/createEntryRevisionFromData.js.map +1 -0
- package/crud/contentEntry/entryDataFactories/createPublishEntryData.d.ts +13 -0
- package/crud/contentEntry/entryDataFactories/createPublishEntryData.js +61 -0
- package/crud/contentEntry/entryDataFactories/createPublishEntryData.js.map +1 -0
- package/crud/contentEntry/entryDataFactories/createRepublishEntryData.d.ts +12 -0
- package/crud/contentEntry/entryDataFactories/createRepublishEntryData.js +57 -0
- package/crud/contentEntry/entryDataFactories/createRepublishEntryData.js.map +1 -0
- package/crud/contentEntry/entryDataFactories/createUnpublishEntryData.d.ts +12 -0
- package/crud/contentEntry/entryDataFactories/createUnpublishEntryData.js +38 -0
- package/crud/contentEntry/entryDataFactories/createUnpublishEntryData.js.map +1 -0
- package/crud/contentEntry/entryDataFactories/createUpdateEntryData.d.ts +20 -0
- package/crud/contentEntry/entryDataFactories/createUpdateEntryData.js +122 -0
- package/crud/contentEntry/entryDataFactories/createUpdateEntryData.js.map +1 -0
- package/crud/contentEntry/entryDataFactories/index.d.ts +8 -0
- package/crud/contentEntry/entryDataFactories/index.js +95 -0
- package/crud/contentEntry/entryDataFactories/index.js.map +1 -0
- package/crud/contentEntry/entryDataFactories/mapAndCleanUpdatedInputData.d.ts +5 -0
- package/crud/contentEntry/entryDataFactories/mapAndCleanUpdatedInputData.js +36 -0
- package/crud/contentEntry/entryDataFactories/mapAndCleanUpdatedInputData.js.map +1 -0
- package/crud/contentEntry/entryDataFactories/statuses.d.ts +4 -0
- package/crud/contentEntry/entryDataFactories/statuses.js +15 -0
- package/crud/contentEntry/entryDataFactories/statuses.js.map +1 -0
- package/crud/contentEntry/entryDataValidation.d.ts +4 -2
- package/crud/contentEntry/entryDataValidation.js +222 -83
- package/crud/contentEntry/entryDataValidation.js.map +1 -1
- package/crud/contentEntry/markLockedFields.d.ts +1 -1
- package/crud/contentEntry/markLockedFields.js +34 -37
- package/crud/contentEntry/markLockedFields.js.map +1 -1
- package/crud/contentEntry/referenceFieldsMapping.d.ts +6 -0
- package/crud/contentEntry/referenceFieldsMapping.js +145 -145
- package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
- package/crud/contentEntry/searchableFields.d.ts +9 -0
- package/crud/contentEntry/searchableFields.js +73 -0
- package/crud/contentEntry/searchableFields.js.map +1 -0
- package/crud/contentEntry.crud.d.ts +9 -5
- package/crud/contentEntry.crud.js +1121 -1070
- package/crud/contentEntry.crud.js.map +1 -1
- package/crud/contentModel/beforeCreate.d.ts +2 -3
- package/crud/contentModel/beforeCreate.js +53 -117
- package/crud/contentModel/beforeCreate.js.map +1 -1
- package/crud/contentModel/beforeDelete.d.ts +1 -1
- package/crud/contentModel/beforeDelete.js +3 -15
- package/crud/contentModel/beforeDelete.js.map +1 -1
- package/crud/contentModel/beforeUpdate.d.ts +2 -4
- package/crud/contentModel/beforeUpdate.js +32 -12
- package/crud/contentModel/beforeUpdate.js.map +1 -1
- package/crud/contentModel/compatibility/modelApiName.d.ts +3 -0
- package/crud/contentModel/compatibility/modelApiName.js +26 -0
- package/crud/contentModel/compatibility/modelApiName.js.map +1 -0
- package/crud/contentModel/contentModelManagerFactory.js +2 -7
- package/crud/contentModel/contentModelManagerFactory.js.map +1 -1
- package/crud/contentModel/createFieldStorageId.js +6 -3
- package/crud/contentModel/createFieldStorageId.js.map +1 -1
- package/crud/contentModel/defaultFields.d.ts +5 -0
- package/crud/contentModel/defaultFields.js +60 -0
- package/crud/contentModel/defaultFields.js.map +1 -0
- package/crud/contentModel/ensureTypeTag.d.ts +5 -0
- package/crud/contentModel/ensureTypeTag.js +21 -0
- package/crud/contentModel/ensureTypeTag.js.map +1 -0
- package/crud/contentModel/fields/descriptionField.d.ts +2 -0
- package/crud/contentModel/fields/descriptionField.js +44 -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 +44 -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 +60 -0
- package/crud/contentModel/fields/titleField.js.map +1 -0
- package/crud/contentModel/listModelsFromDatabase.d.ts +10 -0
- package/crud/contentModel/listModelsFromDatabase.js +38 -0
- package/crud/contentModel/listModelsFromDatabase.js.map +1 -0
- package/crud/contentModel/validate/endingAllowed.d.ts +6 -0
- package/crud/contentModel/validate/endingAllowed.js +28 -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 +26 -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 +38 -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 +26 -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 +26 -0
- package/crud/contentModel/validate/singularApiName.js.map +1 -0
- package/crud/contentModel/validateModel.d.ts +4 -4
- package/crud/contentModel/validateModel.js +8 -11
- package/crud/contentModel/validateModel.js.map +1 -1
- package/crud/contentModel/validateModelFields.d.ts +4 -4
- package/crud/contentModel/validateModelFields.js +136 -152
- package/crud/contentModel/validateModelFields.js.map +1 -1
- package/crud/contentModel/validation.d.ts +872 -0
- package/crud/contentModel/validation.js +205 -0
- package/crud/contentModel/validation.js.map +1 -0
- package/crud/contentModel.crud.d.ts +2 -0
- package/crud/contentModel.crud.js +436 -445
- package/crud/contentModel.crud.js.map +1 -1
- package/crud/contentModelGroup/beforeCreate.d.ts +1 -1
- package/crud/contentModelGroup/beforeCreate.js +14 -12
- package/crud/contentModelGroup/beforeCreate.js.map +1 -1
- package/crud/contentModelGroup/beforeDelete.js +2 -8
- package/crud/contentModelGroup/beforeDelete.js.map +1 -1
- package/crud/contentModelGroup/beforeUpdate.js +2 -5
- package/crud/contentModelGroup/beforeUpdate.js.map +1 -1
- package/crud/contentModelGroup/listGroupsFromDatabase.d.ts +8 -0
- package/crud/contentModelGroup/listGroupsFromDatabase.js +22 -0
- package/crud/contentModelGroup/listGroupsFromDatabase.js.map +1 -0
- package/crud/contentModelGroup/validation.d.ts +33 -0
- package/crud/contentModelGroup/validation.js +37 -0
- package/crud/contentModelGroup/validation.js.map +1 -0
- package/crud/contentModelGroup.crud.d.ts +3 -1
- package/crud/contentModelGroup.crud.js +291 -289
- package/crud/contentModelGroup.crud.js.map +1 -1
- package/crud/system.crud.js +8 -106
- package/crud/system.crud.js.map +1 -1
- package/export/crud/exporting.d.ts +3 -0
- package/export/crud/exporting.js +49 -0
- package/export/crud/exporting.js.map +1 -0
- package/export/crud/importing.d.ts +3 -0
- package/export/crud/importing.js +79 -0
- package/export/crud/importing.js.map +1 -0
- package/export/crud/imports/importData.d.ts +14 -0
- package/export/crud/imports/importData.js +52 -0
- package/export/crud/imports/importData.js.map +1 -0
- package/export/crud/imports/importGroups.d.ts +8 -0
- package/export/crud/imports/importGroups.js +104 -0
- package/export/crud/imports/importGroups.js.map +1 -0
- package/export/crud/imports/importModels.d.ts +8 -0
- package/export/crud/imports/importModels.js +136 -0
- package/export/crud/imports/importModels.js.map +1 -0
- package/export/crud/imports/validateGroups.d.ts +8 -0
- package/export/crud/imports/validateGroups.js +112 -0
- package/export/crud/imports/validateGroups.js.map +1 -0
- package/export/crud/imports/validateInput.d.ts +19 -0
- package/export/crud/imports/validateInput.js +55 -0
- package/export/crud/imports/validateInput.js.map +1 -0
- package/export/crud/imports/validateModels.d.ts +12 -0
- package/export/crud/imports/validateModels.js +203 -0
- package/export/crud/imports/validateModels.js.map +1 -0
- package/export/crud/index.d.ts +4 -0
- package/export/crud/index.js +15 -0
- package/export/crud/index.js.map +1 -0
- package/export/crud/sanitize.d.ts +4 -0
- package/export/crud/sanitize.js +35 -0
- package/export/crud/sanitize.js.map +1 -0
- package/export/graphql/index.d.ts +3 -0
- package/export/graphql/index.js +188 -0
- package/export/graphql/index.js.map +1 -0
- package/export/index.d.ts +2 -0
- package/export/index.js +29 -0
- package/export/index.js.map +1 -0
- package/export/types.d.ts +113 -0
- package/export/types.js +22 -0
- package/export/types.js.map +1 -0
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +3 -19
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.d.ts +11 -0
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +200 -0
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -0
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +46 -90
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/index.d.ts +2 -1
- package/fieldConverters/index.js +4 -5
- package/fieldConverters/index.js.map +1 -1
- package/graphql/buildSchemaPlugins.d.ts +8 -3
- package/graphql/buildSchemaPlugins.js +9 -11
- package/graphql/buildSchemaPlugins.js.map +1 -1
- package/graphql/checkEndpointAccess.d.ts +2 -0
- package/graphql/checkEndpointAccess.js +20 -0
- package/graphql/checkEndpointAccess.js.map +1 -0
- package/graphql/createExecutableSchema.d.ts +6 -0
- package/graphql/createExecutableSchema.js +31 -0
- package/graphql/createExecutableSchema.js.map +1 -0
- package/graphql/createRequestBody.d.ts +2 -0
- package/graphql/createRequestBody.js +16 -0
- package/graphql/createRequestBody.js.map +1 -0
- package/graphql/formatErrorPayload.d.ts +1 -0
- package/graphql/formatErrorPayload.js +27 -0
- package/graphql/formatErrorPayload.js.map +1 -0
- package/graphql/generateSchema.d.ts +8 -0
- package/graphql/generateSchema.js +33 -0
- package/graphql/generateSchema.js.map +1 -0
- package/graphql/getSchema.d.ts +16 -0
- package/graphql/getSchema.js +118 -0
- package/graphql/getSchema.js.map +1 -0
- package/graphql/graphQLHandlerFactory.js +8 -129
- package/graphql/graphQLHandlerFactory.js.map +1 -1
- package/graphql/handleRequest.d.ts +11 -0
- package/graphql/handleRequest.js +79 -0
- package/graphql/handleRequest.js.map +1 -0
- package/graphql/index.d.ts +1 -3
- package/graphql/index.js +4 -46
- package/graphql/index.js.map +1 -1
- package/graphql/schema/baseContentSchema.d.ts +6 -2
- package/graphql/schema/baseContentSchema.js +20 -29
- package/graphql/schema/baseContentSchema.js.map +1 -1
- package/graphql/schema/baseSchema.d.ts +2 -0
- package/graphql/schema/baseSchema.js +146 -0
- package/graphql/schema/baseSchema.js.map +1 -0
- package/graphql/schema/contentEntries.d.ts +6 -2
- package/graphql/schema/contentEntries.js +160 -111
- package/graphql/schema/contentEntries.js.map +1 -1
- package/graphql/schema/contentModelGroups.d.ts +6 -2
- package/graphql/schema/contentModelGroups.js +20 -30
- package/graphql/schema/contentModelGroups.js.map +1 -1
- package/graphql/schema/contentModels.d.ts +6 -2
- package/graphql/schema/contentModels.js +81 -26
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createFieldResolvers.d.ts +2 -2
- package/graphql/schema/createFieldResolvers.js +29 -40
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/graphql/schema/createFieldTypePluginRecords.d.ts +3 -0
- package/graphql/schema/createFieldTypePluginRecords.js +15 -0
- package/graphql/schema/createFieldTypePluginRecords.js.map +1 -0
- package/graphql/schema/createManageResolvers.d.ts +1 -1
- package/graphql/schema/createManageResolvers.js +59 -52
- package/graphql/schema/createManageResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.d.ts +3 -0
- package/graphql/schema/createManageSDL.js +119 -81
- package/graphql/schema/createManageSDL.js.map +1 -1
- package/graphql/schema/createPreviewResolvers.js +9 -22
- package/graphql/schema/createPreviewResolvers.js.map +1 -1
- package/graphql/schema/createReadResolvers.js +14 -22
- package/graphql/schema/createReadResolvers.js.map +1 -1
- package/graphql/schema/createReadSDL.d.ts +3 -0
- package/graphql/schema/createReadSDL.js +57 -48
- package/graphql/schema/createReadSDL.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveCreate.d.ts +2 -1
- package/graphql/schema/resolvers/manage/resolveCreate.js +3 -4
- package/graphql/schema/resolvers/manage/resolveCreate.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveCreateFrom.d.ts +2 -1
- package/graphql/schema/resolvers/manage/resolveCreateFrom.js +3 -4
- 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 +15 -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 +22 -0
- package/graphql/schema/resolvers/manage/resolveDeleteMultiple.js.map +1 -0
- package/graphql/schema/resolvers/manage/resolveGet.js +11 -20
- package/graphql/schema/resolvers/manage/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGetByIds.js +2 -3
- package/graphql/schema/resolvers/manage/resolveGetByIds.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGetRevisions.js +2 -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 +20 -0
- package/graphql/schema/resolvers/manage/resolveGetUniqueFieldValues.js.map +1 -0
- package/graphql/schema/resolvers/manage/resolveList.js +2 -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 +27 -0
- package/graphql/schema/resolvers/manage/resolveMove.js.map +1 -0
- package/graphql/schema/resolvers/manage/resolvePublish.js +2 -3
- package/graphql/schema/resolvers/manage/resolvePublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveRepublish.js +2 -3
- package/graphql/schema/resolvers/manage/resolveRepublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveUnpublish.js +2 -3
- package/graphql/schema/resolvers/manage/resolveUnpublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveUpdate.d.ts +2 -1
- package/graphql/schema/resolvers/manage/resolveUpdate.js +3 -4
- package/graphql/schema/resolvers/manage/resolveUpdate.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveValidate.d.ts +8 -0
- package/graphql/schema/resolvers/manage/{resolveRequestChanges.js → resolveValidate.js} +5 -6
- package/graphql/schema/resolvers/manage/resolveValidate.js.map +1 -0
- package/graphql/schema/resolvers/preview/resolveGet.js +5 -12
- package/graphql/schema/resolvers/preview/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/preview/resolveList.js +2 -3
- package/graphql/schema/resolvers/preview/resolveList.js.map +1 -1
- package/graphql/schema/resolvers/read/resolveGet.js +5 -12
- package/graphql/schema/resolvers/read/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/read/resolveList.js +2 -3
- package/graphql/schema/resolvers/read/resolveList.js.map +1 -1
- package/graphql/schema/schemaPlugins.d.ts +8 -3
- package/graphql/schema/schemaPlugins.js +60 -69
- package/graphql/schema/schemaPlugins.js.map +1 -1
- package/graphql/system.d.ts +2 -5
- package/graphql/system.js +58 -98
- package/graphql/system.js.map +1 -1
- package/graphqlFields/boolean.js +2 -12
- package/graphqlFields/boolean.js.map +1 -1
- package/graphqlFields/datetime.js +4 -21
- package/graphqlFields/datetime.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +2 -0
- package/graphqlFields/dynamicZone/dynamicZoneField.js +266 -0
- package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.d.ts +3 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js +111 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js.map +1 -0
- package/graphqlFields/dynamicZone/index.d.ts +2 -0
- package/graphqlFields/dynamicZone/index.js +21 -0
- package/graphqlFields/dynamicZone/index.js.map +1 -0
- package/graphqlFields/file.js +2 -8
- package/graphqlFields/file.js.map +1 -1
- package/graphqlFields/helpers.d.ts +0 -1
- package/graphqlFields/helpers.js +5 -27
- package/graphqlFields/helpers.js.map +1 -1
- package/graphqlFields/index.d.ts +1 -1
- package/graphqlFields/index.js +5 -12
- package/graphqlFields/index.js.map +1 -1
- package/graphqlFields/json.d.ts +2 -0
- package/graphqlFields/json.js +49 -0
- package/graphqlFields/json.js.map +1 -0
- package/graphqlFields/longText.js +13 -12
- package/graphqlFields/longText.js.map +1 -1
- package/graphqlFields/number.js +7 -12
- package/graphqlFields/number.js.map +1 -1
- package/graphqlFields/object.js +114 -101
- package/graphqlFields/object.js.map +1 -1
- package/graphqlFields/ref.js +111 -119
- package/graphqlFields/ref.js.map +1 -1
- package/graphqlFields/richText.js +2 -9
- package/graphqlFields/richText.js.map +1 -1
- package/graphqlFields/text.js +4 -11
- package/graphqlFields/text.js.map +1 -1
- package/index.d.ts +6 -3
- package/index.js +43 -29
- package/index.js.map +1 -1
- package/modelManager/DefaultCmsModelManager.js +2 -20
- package/modelManager/DefaultCmsModelManager.js.map +1 -1
- package/modelManager/index.js +2 -4
- package/modelManager/index.js.map +1 -1
- package/package.json +36 -43
- package/parameters/context.js +3 -5
- package/parameters/context.js.map +1 -1
- package/parameters/header.js +6 -16
- package/parameters/header.js.map +1 -1
- package/parameters/index.js +3 -9
- package/parameters/index.js.map +1 -1
- package/parameters/manual.js +9 -11
- package/parameters/manual.js.map +1 -1
- package/parameters/path.js +3 -13
- package/parameters/path.js.map +1 -1
- package/plugins/CmsGraphQLSchemaPlugin.d.ts +5 -0
- package/plugins/CmsGraphQLSchemaPlugin.js +13 -0
- package/plugins/CmsGraphQLSchemaPlugin.js.map +1 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.d.ts +20 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.js +27 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.js.map +1 -0
- package/plugins/CmsGroupPlugin.d.ts +6 -3
- package/plugins/CmsGroupPlugin.js +7 -13
- package/plugins/CmsGroupPlugin.js.map +1 -1
- package/plugins/CmsModelFieldConverterPlugin.d.ts +2 -2
- package/plugins/CmsModelFieldConverterPlugin.js +5 -9
- package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
- package/plugins/CmsModelPlugin.d.ts +25 -5
- package/plugins/CmsModelPlugin.js +72 -57
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/plugins/CmsParametersPlugin.js +6 -10
- package/plugins/CmsParametersPlugin.js.map +1 -1
- package/plugins/StorageOperationsCmsModelPlugin.d.ts +23 -0
- package/plugins/StorageOperationsCmsModelPlugin.js +41 -0
- package/plugins/StorageOperationsCmsModelPlugin.js.map +1 -0
- package/plugins/StorageTransformPlugin.d.ts +13 -13
- package/plugins/StorageTransformPlugin.js +3 -13
- package/plugins/StorageTransformPlugin.js.map +1 -1
- package/plugins/index.d.ts +3 -0
- package/plugins/index.js +36 -11
- package/plugins/index.js.map +1 -1
- package/storage/default.js +2 -3
- package/storage/default.js.map +1 -1
- package/storage/index.d.ts +1 -0
- package/storage/index.js +15 -0
- package/storage/index.js.map +1 -0
- package/storage/json.d.ts +2 -0
- package/storage/json.js +27 -0
- package/storage/json.js.map +1 -0
- package/storage/object.js +11 -27
- package/storage/object.js.map +1 -1
- package/types.d.ts +755 -384
- package/types.js +83 -90
- package/types.js.map +1 -1
- package/utils/access.d.ts +9 -8
- package/utils/access.js +11 -75
- package/utils/access.js.map +1 -1
- package/utils/caching/Cache.d.ts +2 -0
- package/utils/caching/Cache.js +51 -0
- package/utils/caching/Cache.js.map +1 -0
- package/utils/caching/CacheKey.d.ts +2 -0
- package/utils/caching/CacheKey.js +40 -0
- package/utils/caching/CacheKey.js.map +1 -0
- package/utils/caching/index.d.ts +2 -0
- package/utils/caching/index.js +29 -0
- package/utils/caching/index.js.map +1 -0
- package/utils/caching/types.d.ts +11 -0
- package/utils/caching/types.js +7 -0
- package/utils/caching/types.js.map +1 -0
- package/utils/converters/Converter.js +3 -17
- package/utils/converters/Converter.js.map +1 -1
- package/utils/converters/ConverterCollection.d.ts +7 -0
- package/utils/converters/ConverterCollection.js +43 -31
- package/utils/converters/ConverterCollection.js.map +1 -1
- package/utils/converters/valueKeyStorageConverter.d.ts +1 -5
- package/utils/converters/valueKeyStorageConverter.js +32 -45
- package/utils/converters/valueKeyStorageConverter.js.map +1 -1
- package/utils/createTypeFromFields.d.ts +16 -0
- package/utils/createTypeFromFields.js +71 -0
- package/utils/createTypeFromFields.js.map +1 -0
- package/utils/createTypeName.d.ts +0 -2
- package/utils/createTypeName.js +4 -17
- package/utils/createTypeName.js.map +1 -1
- package/utils/date.d.ts +10 -0
- package/utils/date.js +36 -0
- package/utils/date.js.map +1 -0
- package/utils/entryStorage.d.ts +4 -4
- package/utils/entryStorage.js +27 -38
- package/utils/entryStorage.js.map +1 -1
- package/utils/filterAsync.js +8 -12
- package/utils/filterAsync.js.map +1 -1
- package/utils/getBaseFieldType.d.ts +2 -0
- package/utils/getBaseFieldType.js +12 -0
- package/utils/getBaseFieldType.js.map +1 -0
- package/utils/getEntryDescription.d.ts +2 -0
- package/utils/getEntryDescription.js +19 -0
- package/utils/getEntryDescription.js.map +1 -0
- package/utils/getEntryImage.d.ts +2 -0
- package/utils/getEntryImage.js +19 -0
- package/utils/getEntryImage.js.map +1 -0
- package/utils/getEntryTitle.d.ts +1 -1
- package/utils/getEntryTitle.js +3 -10
- package/utils/getEntryTitle.js.map +1 -1
- package/utils/getSchemaFromFieldPlugins.d.ts +14 -6
- package/utils/getSchemaFromFieldPlugins.js +39 -17
- package/utils/getSchemaFromFieldPlugins.js.map +1 -1
- package/utils/identity.d.ts +2 -0
- package/utils/identity.js +20 -0
- package/utils/identity.js.map +1 -0
- package/utils/incrementEntryIdVersion.d.ts +5 -0
- package/utils/incrementEntryIdVersion.js +31 -0
- package/utils/incrementEntryIdVersion.js.map +1 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +18 -0
- package/utils/index.js.map +1 -0
- package/utils/permissions/EntriesPermissions.d.ts +4 -0
- package/utils/permissions/EntriesPermissions.js +11 -0
- package/utils/permissions/EntriesPermissions.js.map +1 -0
- package/utils/permissions/ModelGroupsPermissions.d.ts +9 -0
- package/utils/permissions/ModelGroupsPermissions.js +50 -0
- package/utils/permissions/ModelGroupsPermissions.js.map +1 -0
- package/utils/permissions/ModelsPermissions.d.ts +22 -0
- package/utils/permissions/ModelsPermissions.js +90 -0
- package/utils/permissions/ModelsPermissions.js.map +1 -0
- package/utils/renderFields.d.ts +4 -2
- package/utils/renderFields.js +14 -11
- package/utils/renderFields.js.map +1 -1
- package/utils/renderGetFilterFields.d.ts +2 -2
- package/utils/renderGetFilterFields.js +10 -30
- package/utils/renderGetFilterFields.js.map +1 -1
- package/utils/renderInputFields.d.ts +4 -2
- package/utils/renderInputFields.js +21 -14
- package/utils/renderInputFields.js.map +1 -1
- package/utils/renderListFilterFields.d.ts +3 -1
- package/utils/renderListFilterFields.js +27 -30
- package/utils/renderListFilterFields.js.map +1 -1
- package/utils/renderSortEnum.d.ts +9 -5
- package/utils/renderSortEnum.js +29 -12
- package/utils/renderSortEnum.js.map +1 -1
- package/utils/toSlug.js +2 -4
- package/utils/toSlug.js.map +1 -1
- package/validators/dateGte.js +2 -7
- package/validators/dateGte.js.map +1 -1
- package/validators/dateLte.js +2 -7
- package/validators/dateLte.js.map +1 -1
- package/validators/gte.js +3 -10
- package/validators/gte.js.map +1 -1
- package/validators/in.js +3 -10
- package/validators/in.js.map +1 -1
- package/validators/index.js +2 -15
- package/validators/index.js.map +1 -1
- package/validators/lte.js +3 -10
- package/validators/lte.js.map +1 -1
- package/validators/maxLength.js +3 -10
- package/validators/maxLength.js.map +1 -1
- package/validators/minLength.js +3 -10
- package/validators/minLength.js.map +1 -1
- package/validators/pattern.js +4 -11
- package/validators/pattern.js.map +1 -1
- package/validators/patternPlugins/email.js +2 -2
- package/validators/patternPlugins/email.js.map +1 -1
- package/validators/patternPlugins/index.js +2 -8
- package/validators/patternPlugins/index.js.map +1 -1
- package/validators/patternPlugins/lowerCase.js +2 -2
- package/validators/patternPlugins/lowerCase.js.map +1 -1
- package/validators/patternPlugins/lowerCaseSpace.js +2 -2
- package/validators/patternPlugins/lowerCaseSpace.js.map +1 -1
- package/validators/patternPlugins/upperCase.js +2 -2
- package/validators/patternPlugins/upperCase.js.map +1 -1
- package/validators/patternPlugins/upperCaseSpace.js +2 -2
- package/validators/patternPlugins/upperCaseSpace.js.map +1 -1
- package/validators/patternPlugins/url.js +2 -2
- package/validators/patternPlugins/url.js.map +1 -1
- package/validators/required.js +2 -5
- package/validators/required.js.map +1 -1
- package/validators/timeGte.js +3 -10
- package/validators/timeGte.js.map +1 -1
- package/validators/timeLte.js +3 -10
- package/validators/timeLte.js.map +1 -1
- package/validators/unique.js +3 -8
- package/validators/unique.js.map +1 -1
- package/crud/contentModel/afterCreate.d.ts +0 -8
- package/crud/contentModel/afterCreate.js +0 -18
- package/crud/contentModel/afterCreate.js.map +0 -1
- package/crud/contentModel/afterCreateFrom.d.ts +0 -8
- package/crud/contentModel/afterCreateFrom.js +0 -18
- package/crud/contentModel/afterCreateFrom.js.map +0 -1
- package/crud/contentModel/afterDelete.d.ts +0 -8
- package/crud/contentModel/afterDelete.js +0 -18
- package/crud/contentModel/afterDelete.js.map +0 -1
- package/crud/contentModel/afterUpdate.d.ts +0 -8
- package/crud/contentModel/afterUpdate.js +0 -18
- package/crud/contentModel/afterUpdate.js.map +0 -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 -180
- 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/contentModel/validateLayout.d.ts +0 -2
- package/crud/contentModel/validateLayout.js +0 -36
- package/crud/contentModel/validateLayout.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/crud/settings.crud.d.ts +0 -10
- package/crud/settings.crud.js +0 -83
- package/crud/settings.crud.js.map +0 -1
- package/graphql/schema/resolvers/commonFieldResolvers.d.ts +0 -6
- package/graphql/schema/resolvers/commonFieldResolvers.js +0 -14
- package/graphql/schema/resolvers/commonFieldResolvers.js.map +0 -1
- package/graphql/schema/resolvers/manage/resolveRequestChanges.d.ts +0 -7
- 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/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,20 +1,14 @@
|
|
|
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.referenceFieldsMapping = void 0;
|
|
9
|
-
|
|
10
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
8
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
-
|
|
14
9
|
var _dotProp = _interopRequireDefault(require("dot-prop"));
|
|
15
|
-
|
|
16
10
|
var _utils = require("@webiny/utils");
|
|
17
|
-
|
|
11
|
+
var _getBaseFieldType = require("../../utils/getBaseFieldType");
|
|
18
12
|
const buildReferenceFieldPaths = params => {
|
|
19
13
|
const {
|
|
20
14
|
fields,
|
|
@@ -23,101 +17,120 @@ const buildReferenceFieldPaths = params => {
|
|
|
23
17
|
} = params;
|
|
24
18
|
const parentPaths = [...initialParentPaths];
|
|
25
19
|
const isMultipleValues = Array.isArray(input);
|
|
26
|
-
return fields.filter(field => ["object", "ref"].includes(
|
|
27
|
-
var _field$settings2;
|
|
28
|
-
|
|
20
|
+
return fields.filter(field => ["object", "ref", "dynamicZone"].includes((0, _getBaseFieldType.getBaseFieldType)(field))).reduce((collection, field) => {
|
|
29
21
|
/**
|
|
30
22
|
* First we check the ref field
|
|
31
23
|
*/
|
|
32
|
-
|
|
24
|
+
const baseType = (0, _getBaseFieldType.getBaseFieldType)(field);
|
|
25
|
+
if (baseType === "ref") {
|
|
33
26
|
const parentPathsValue = parentPaths.length > 0 ? `${parentPaths.join(".")}.` : "";
|
|
34
|
-
|
|
35
27
|
if (field.multipleValues) {
|
|
36
28
|
const inputValue = _dotProp.default.get(input, `${field.fieldId}`, []);
|
|
37
|
-
|
|
38
|
-
if (Array.isArray(inputValue) === false) {
|
|
29
|
+
if (!Array.isArray(inputValue)) {
|
|
39
30
|
return collection;
|
|
40
31
|
}
|
|
41
|
-
|
|
42
32
|
for (const key in inputValue) {
|
|
43
33
|
const path = `${parentPathsValue}${field.fieldId}.${key}`;
|
|
44
34
|
collection.push(path);
|
|
45
35
|
}
|
|
46
|
-
|
|
47
36
|
return collection;
|
|
48
37
|
}
|
|
49
|
-
|
|
50
38
|
if (isMultipleValues) {
|
|
51
39
|
for (const key in input) {
|
|
52
40
|
const path = `${parentPathsValue}${key}.${field.fieldId}`;
|
|
53
41
|
collection.push(path);
|
|
54
42
|
}
|
|
55
|
-
|
|
56
43
|
return collection;
|
|
57
44
|
}
|
|
58
|
-
|
|
59
45
|
collection.push(`${parentPathsValue}${field.fieldId}`);
|
|
60
46
|
return collection;
|
|
61
47
|
}
|
|
48
|
+
if (baseType === "dynamicZone") {
|
|
49
|
+
const templates = field.settings?.templates || [];
|
|
50
|
+
if (field.multipleValues) {
|
|
51
|
+
const values = _dotProp.default.get(input, field.fieldId, []);
|
|
52
|
+
if (!Array.isArray(values)) {
|
|
53
|
+
return collection;
|
|
54
|
+
}
|
|
55
|
+
values.forEach((value, index) => {
|
|
56
|
+
const valueTemplate = Object.keys(value)[0];
|
|
57
|
+
const template = templates.find(tpl => tpl.gqlTypeName === valueTemplate);
|
|
58
|
+
if (!template) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const result = buildReferenceFieldPaths({
|
|
62
|
+
fields: template.fields,
|
|
63
|
+
input: value[valueTemplate],
|
|
64
|
+
parentPaths: parentPaths.concat([field.fieldId, String(index), template.gqlTypeName])
|
|
65
|
+
});
|
|
66
|
+
collection.push(...result);
|
|
67
|
+
});
|
|
68
|
+
return collection;
|
|
69
|
+
}
|
|
70
|
+
const value = _dotProp.default.get(input, field.fieldId, {});
|
|
71
|
+
if (!value) {
|
|
72
|
+
return collection;
|
|
73
|
+
}
|
|
74
|
+
const valueTemplate = Object.keys(value)[0];
|
|
75
|
+
const template = templates.find(tpl => tpl.gqlTypeName === valueTemplate);
|
|
76
|
+
if (!template) {
|
|
77
|
+
return collection;
|
|
78
|
+
}
|
|
79
|
+
const result = buildReferenceFieldPaths({
|
|
80
|
+
fields: template.fields,
|
|
81
|
+
input: _dotProp.default.get(value, valueTemplate, {}),
|
|
82
|
+
parentPaths: parentPaths.concat([field.fieldId, template.gqlTypeName])
|
|
83
|
+
});
|
|
84
|
+
collection.push(...result);
|
|
85
|
+
return collection;
|
|
86
|
+
}
|
|
87
|
+
|
|
62
88
|
/**
|
|
63
89
|
* Then we move onto the object field
|
|
64
90
|
*/
|
|
65
|
-
|
|
66
|
-
|
|
67
91
|
const parentPathsValue = parentPaths.length > 0 ? `${parentPaths.join(".")}.` : "";
|
|
68
92
|
/**
|
|
69
93
|
* This is if received input is array. We need to map key with fieldId at this point.
|
|
70
94
|
*/
|
|
71
|
-
|
|
72
95
|
if (isMultipleValues) {
|
|
73
96
|
for (const key in input) {
|
|
74
97
|
const path = `${parentPathsValue}${key}.${field.fieldId}`;
|
|
75
98
|
collection.push(path);
|
|
76
99
|
}
|
|
77
|
-
|
|
78
100
|
return collection;
|
|
79
101
|
}
|
|
80
|
-
|
|
81
102
|
const objFieldPath = `${field.fieldId}`;
|
|
82
|
-
|
|
83
103
|
const objFieldInputValue = _dotProp.default.get(input, objFieldPath, []);
|
|
104
|
+
|
|
84
105
|
/**
|
|
85
106
|
* If field is multiple values one, we need to go through the input and use the existing keys.
|
|
86
107
|
*/
|
|
87
|
-
|
|
88
|
-
|
|
89
108
|
if (field.multipleValues) {
|
|
90
109
|
if (Array.isArray(objFieldInputValue) === false) {
|
|
91
110
|
return collection;
|
|
92
111
|
}
|
|
93
|
-
|
|
94
112
|
for (const key in objFieldInputValue) {
|
|
95
|
-
var _field$settings;
|
|
96
|
-
|
|
97
113
|
const result = buildReferenceFieldPaths({
|
|
98
|
-
fields:
|
|
114
|
+
fields: field.settings?.fields || [],
|
|
99
115
|
input: objFieldInputValue[key],
|
|
100
116
|
parentPaths: parentPaths.concat([field.fieldId, key])
|
|
101
117
|
});
|
|
102
118
|
collection.push(...result);
|
|
103
119
|
}
|
|
104
|
-
|
|
105
120
|
return collection;
|
|
106
121
|
}
|
|
122
|
+
|
|
107
123
|
/**
|
|
108
124
|
* Single value reference field.
|
|
109
125
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
112
126
|
const results = buildReferenceFieldPaths({
|
|
113
|
-
fields:
|
|
127
|
+
fields: field.settings?.fields || [],
|
|
114
128
|
input: objFieldInputValue,
|
|
115
129
|
parentPaths: parentPaths.concat([field.fieldId])
|
|
116
130
|
});
|
|
117
131
|
return collection.concat(results);
|
|
118
132
|
}, []);
|
|
119
133
|
};
|
|
120
|
-
|
|
121
134
|
const getReferenceFieldValue = ref => {
|
|
122
135
|
if (!ref) {
|
|
123
136
|
return {
|
|
@@ -125,13 +138,18 @@ const getReferenceFieldValue = ref => {
|
|
|
125
138
|
modelId: null
|
|
126
139
|
};
|
|
127
140
|
}
|
|
128
|
-
|
|
129
141
|
return {
|
|
130
142
|
id: (ref.id || ref.entryId || "").trim() || null,
|
|
131
143
|
modelId: (ref.modelId || "").trim() || null
|
|
132
144
|
};
|
|
133
145
|
};
|
|
134
146
|
|
|
147
|
+
/**
|
|
148
|
+
* This function traverses the content entry input value, extracts all occurrences of the `ref` field,
|
|
149
|
+
* optionally verifies that those referenced entries exist (by loading them), and normalizes the `ref` value to
|
|
150
|
+
* always contain `{ id, modelId, entryId }`. `entryId` is important when data is being loaded via
|
|
151
|
+
* the `read` and `preview` endpoint.
|
|
152
|
+
*/
|
|
135
153
|
const referenceFieldsMapping = async params => {
|
|
136
154
|
const {
|
|
137
155
|
context,
|
|
@@ -139,150 +157,132 @@ const referenceFieldsMapping = async params => {
|
|
|
139
157
|
input,
|
|
140
158
|
validateEntries = false
|
|
141
159
|
} = params;
|
|
142
|
-
let output =
|
|
160
|
+
let output = {
|
|
161
|
+
...input
|
|
162
|
+
};
|
|
143
163
|
const referenceFieldPaths = buildReferenceFieldPaths({
|
|
144
164
|
fields: model.fields,
|
|
145
165
|
input,
|
|
146
166
|
parentPaths: []
|
|
147
167
|
});
|
|
148
|
-
|
|
149
|
-
if (referenceFieldPaths.length === 0) {
|
|
168
|
+
if (!referenceFieldPaths.length) {
|
|
150
169
|
return output;
|
|
151
170
|
}
|
|
171
|
+
if (validateEntries) {
|
|
172
|
+
await validateReferencedEntries({
|
|
173
|
+
output,
|
|
174
|
+
context,
|
|
175
|
+
referenceFieldPaths
|
|
176
|
+
});
|
|
177
|
+
}
|
|
152
178
|
|
|
153
|
-
|
|
154
|
-
|
|
179
|
+
/**
|
|
180
|
+
* Assign the entryId, id and model values to the output.
|
|
181
|
+
*/
|
|
182
|
+
for (const path of referenceFieldPaths) {
|
|
183
|
+
// It is safe to cast here, because `referenceFieldPaths` array is generated from the `input`.
|
|
184
|
+
const refValue = _dotProp.default.get(input, path);
|
|
185
|
+
if (!refValue) {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
155
188
|
|
|
189
|
+
/**
|
|
190
|
+
* Over time, the structure of `RefInput` was changing, and we need to handle different cases for backwards
|
|
191
|
+
* compatibility. The latest valid structure of a `ref` field value is { id, modelId }, but we also need
|
|
192
|
+
* to make sure that the legacy structure { entryId, modelId } is supported.
|
|
193
|
+
*/
|
|
194
|
+
const {
|
|
195
|
+
id,
|
|
196
|
+
modelId,
|
|
197
|
+
entryId: maybeEntryId
|
|
198
|
+
} = refValue;
|
|
199
|
+
const {
|
|
200
|
+
id: entryId
|
|
201
|
+
} = (0, _utils.parseIdentifier)(maybeEntryId || id);
|
|
202
|
+
output = _dotProp.default.set(output, path, {
|
|
203
|
+
// If `id` is not set, we're dealing with the legacy structure.
|
|
204
|
+
id: id ?? maybeEntryId,
|
|
205
|
+
entryId,
|
|
206
|
+
modelId
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
return output;
|
|
210
|
+
};
|
|
211
|
+
exports.referenceFieldsMapping = referenceFieldsMapping;
|
|
212
|
+
async function validateReferencedEntries({
|
|
213
|
+
output,
|
|
214
|
+
context,
|
|
215
|
+
referenceFieldPaths
|
|
216
|
+
}) {
|
|
217
|
+
const referencesByModel = new Map();
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Group references by modelId.
|
|
221
|
+
*/
|
|
156
222
|
for (const path of referenceFieldPaths) {
|
|
157
223
|
const ref = _dotProp.default.get(output, path);
|
|
158
|
-
|
|
159
224
|
const {
|
|
160
225
|
id,
|
|
161
226
|
modelId
|
|
162
227
|
} = getReferenceFieldValue(ref);
|
|
163
|
-
|
|
164
228
|
if (!id || !modelId) {
|
|
165
229
|
continue;
|
|
166
230
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
referencesByModel[modelId] = [];
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
referencesByModel[modelId].push(id);
|
|
173
|
-
|
|
174
|
-
if (!pathsByReferenceId[id]) {
|
|
175
|
-
pathsByReferenceId[id] = [];
|
|
231
|
+
if (!referencesByModel.has(modelId)) {
|
|
232
|
+
referencesByModel.set(modelId, []);
|
|
176
233
|
}
|
|
177
|
-
|
|
178
|
-
pathsByReferenceId[id].push(path);
|
|
234
|
+
referencesByModel.get(modelId)?.push(id);
|
|
179
235
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
*/
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
if (Object.keys(referencesByModel).length === 0) {
|
|
186
|
-
return output;
|
|
236
|
+
if (!referencesByModel.size) {
|
|
237
|
+
return;
|
|
187
238
|
}
|
|
239
|
+
|
|
188
240
|
/**
|
|
189
241
|
* Load all models and use only those that are used in reference.
|
|
190
242
|
*/
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
return
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return true;
|
|
243
|
+
const models = await context.security.withoutAuthorization(async () => {
|
|
244
|
+
return (await context.cms.listModels()).filter(model => {
|
|
245
|
+
const entries = referencesByModel.get(model.modelId);
|
|
246
|
+
if (!Array.isArray(entries) || entries.length === 0) {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
return true;
|
|
250
|
+
});
|
|
201
251
|
});
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
*/
|
|
205
|
-
|
|
206
|
-
if (models.length === 0) {
|
|
207
|
-
return output;
|
|
252
|
+
if (!models.length) {
|
|
253
|
+
return;
|
|
208
254
|
}
|
|
255
|
+
|
|
209
256
|
/**
|
|
210
|
-
* Load all the entries by their
|
|
257
|
+
* Load all the entries by their IDs.
|
|
211
258
|
*/
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
259
|
+
const promises = await context.security.withoutAuthorization(async () => {
|
|
260
|
+
return models.map(model => {
|
|
261
|
+
return context.cms.getEntriesByIds(model, referencesByModel.get(model.modelId) || []);
|
|
262
|
+
});
|
|
216
263
|
});
|
|
217
|
-
const
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
modelId: entry.modelId
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
return collection;
|
|
264
|
+
const allEntries = await Promise.all(promises).then(res => res.flat());
|
|
265
|
+
const entriesByModel = allEntries.reduce((acc, entry) => {
|
|
266
|
+
return {
|
|
267
|
+
...acc,
|
|
268
|
+
[entry.modelId]: [...(acc[entry.modelId] || []), entry.id]
|
|
269
|
+
};
|
|
228
270
|
}, {});
|
|
271
|
+
|
|
229
272
|
/**
|
|
230
|
-
* Verify that all
|
|
273
|
+
* Verify that all entries exist.
|
|
231
274
|
*/
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
for (const id of entries) {
|
|
237
|
-
if (records[id]) {
|
|
238
|
-
continue;
|
|
239
|
-
} else if (validateEntries === true) {
|
|
275
|
+
referencesByModel.forEach((ids, modelId) => {
|
|
276
|
+
const modelEntriesInDb = entriesByModel[modelId];
|
|
277
|
+
for (const id of ids) {
|
|
278
|
+
if (!modelEntriesInDb.includes(id)) {
|
|
240
279
|
throw new _error.default(`Missing referenced entry with id "${id}" in model "${modelId}".`, "ENTRY_NOT_FOUND", {
|
|
241
280
|
id,
|
|
242
281
|
model: modelId
|
|
243
282
|
});
|
|
244
283
|
}
|
|
245
|
-
|
|
246
|
-
const {
|
|
247
|
-
id: entryId
|
|
248
|
-
} = (0, _utils.parseIdentifier)(id);
|
|
249
|
-
records[id] = {
|
|
250
|
-
id,
|
|
251
|
-
entryId,
|
|
252
|
-
modelId
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* In the end, assign the entryId, id and model values to the output.
|
|
258
|
-
*/
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
for (const id in pathsByReferenceId) {
|
|
262
|
-
const entry = records[id];
|
|
263
|
-
const paths = pathsByReferenceId[id];
|
|
264
|
-
|
|
265
|
-
if (!entry) {
|
|
266
|
-
if (validateEntries === true) {
|
|
267
|
-
throw new _error.default("Missing entry in records.", "ENTRY_ERROR", {
|
|
268
|
-
id,
|
|
269
|
-
paths
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
continue;
|
|
274
284
|
}
|
|
285
|
+
});
|
|
286
|
+
}
|
|
275
287
|
|
|
276
|
-
|
|
277
|
-
output = _dotProp.default.set(output, path, {
|
|
278
|
-
id: entry.id,
|
|
279
|
-
entryId: entry.entryId,
|
|
280
|
-
modelId: entry.modelId
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
return output;
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
exports.referenceFieldsMapping = referenceFieldsMapping;
|
|
288
|
+
//# sourceMappingURL=referenceFieldsMapping.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["buildReferenceFieldPaths","params","fields","parentPaths","initialParentPaths","input","isMultipleValues","Array","isArray","filter","field","includes","type","reduce","collection","parentPathsValue","length","join","multipleValues","inputValue","dotProp","get","fieldId","key","path","push","objFieldPath","objFieldInputValue","result","settings","concat","results","getReferenceFieldValue","ref","id","modelId","entryId","trim","referenceFieldsMapping","context","model","validateEntries","output","referenceFieldPaths","referencesByModel","pathsByReferenceId","Object","keys","models","cms","listModels","entries","promises","map","getEntriesByIds","Promise","all","records","entry","WebinyError","parseIdentifier","paths","set"],"sources":["referenceFieldsMapping.ts"],"sourcesContent":["import { CmsContext, CmsModel, CmsModelField } from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport dotProp from \"dot-prop\";\nimport { parseIdentifier } from \"@webiny/utils\";\n\ninterface CmsRefEntry {\n id: string;\n entryId: string;\n modelId: string;\n}\n\ninterface ReferenceObject {\n id: string;\n modelId: string;\n}\n\ninterface Params {\n context: CmsContext;\n model: CmsModel;\n input: Record<string, ReferenceObject | ReferenceObject[]>;\n validateEntries?: boolean;\n}\n\ninterface BuildReferenceFieldPaths {\n fields: CmsModelField[];\n parentPaths: string[];\n input: Record<string, any>;\n}\n\nconst buildReferenceFieldPaths = (params: BuildReferenceFieldPaths): string[] => {\n const { fields, parentPaths: initialParentPaths, input } = params;\n\n const parentPaths = [...initialParentPaths];\n\n const isMultipleValues = Array.isArray(input);\n\n return fields\n .filter(field => [\"object\", \"ref\"].includes(field.type))\n .reduce((collection, field) => {\n /**\n * First we check the ref field\n */\n if (field.type === \"ref\") {\n const parentPathsValue = parentPaths.length > 0 ? `${parentPaths.join(\".\")}.` : \"\";\n if (field.multipleValues) {\n const inputValue = dotProp.get(input, `${field.fieldId}`, []);\n if (Array.isArray(inputValue) === false) {\n return collection;\n }\n for (const key in inputValue) {\n const path = `${parentPathsValue}${field.fieldId}.${key}`;\n collection.push(path);\n }\n return collection;\n }\n\n if (isMultipleValues) {\n for (const key in input) {\n const path = `${parentPathsValue}${key}.${field.fieldId}`;\n collection.push(path);\n }\n return collection;\n }\n\n collection.push(`${parentPathsValue}${field.fieldId}`);\n\n return collection;\n }\n /**\n * Then we move onto the object field\n */\n const parentPathsValue = parentPaths.length > 0 ? `${parentPaths.join(\".\")}.` : \"\";\n /**\n * This is if received input is array. We need to map key with fieldId at this point.\n */\n if (isMultipleValues) {\n for (const key in input) {\n const path = `${parentPathsValue}${key}.${field.fieldId}`;\n collection.push(path);\n }\n return collection;\n }\n\n const objFieldPath = `${field.fieldId}`;\n const objFieldInputValue = dotProp.get(input, objFieldPath, []);\n\n /**\n * If field is multiple values one, we need to go through the input and use the existing keys.\n */\n if (field.multipleValues) {\n if (Array.isArray(objFieldInputValue) === false) {\n return collection;\n }\n for (const key in objFieldInputValue) {\n const result = buildReferenceFieldPaths({\n fields: field.settings?.fields || [],\n input: objFieldInputValue[key],\n parentPaths: parentPaths.concat([field.fieldId, key])\n });\n collection.push(...result);\n }\n\n return collection;\n }\n\n /**\n * Single value reference field.\n */\n const results = buildReferenceFieldPaths({\n fields: field.settings?.fields || [],\n input: objFieldInputValue,\n parentPaths: parentPaths.concat([field.fieldId])\n });\n\n return collection.concat(results);\n }, [] as string[]);\n};\n\nconst getReferenceFieldValue = (ref: any): { id: string | null; modelId: string | null } => {\n if (!ref) {\n return {\n id: null,\n modelId: null\n };\n }\n return {\n id: (ref.id || ref.entryId || \"\").trim() || null,\n modelId: (ref.modelId || \"\").trim() || null\n };\n};\n\nexport const referenceFieldsMapping = async (params: Params): Promise<Record<string, any>> => {\n const { context, model, input, validateEntries = false } = params;\n\n let output: Record<string, any> = {\n ...input\n };\n\n const referenceFieldPaths = buildReferenceFieldPaths({\n fields: model.fields,\n input,\n parentPaths: []\n });\n if (referenceFieldPaths.length === 0) {\n return output;\n }\n\n const referencesByModel: Record<string, string[]> = {};\n const pathsByReferenceId: Record<string, string[]> = {};\n\n for (const path of referenceFieldPaths) {\n const ref = dotProp.get(output, path) as ReferenceObject | any;\n\n const { id, modelId } = getReferenceFieldValue(ref);\n\n if (!id || !modelId) {\n continue;\n }\n if (!referencesByModel[modelId]) {\n referencesByModel[modelId] = [];\n }\n referencesByModel[modelId].push(id);\n if (!pathsByReferenceId[id]) {\n pathsByReferenceId[id] = [];\n }\n pathsByReferenceId[id].push(path);\n }\n\n /**\n * Again, no point in going further.\n */\n if (Object.keys(referencesByModel).length === 0) {\n return output;\n }\n /**\n * Load all models and use only those that are used in reference.\n */\n const models = (await context.cms.listModels()).filter(model => {\n const entries = referencesByModel[model.modelId];\n if (Array.isArray(entries) === false || entries.length === 0) {\n return false;\n }\n return true;\n });\n /**\n * Check for any model existence, just in case.\n */\n if (models.length === 0) {\n return output;\n }\n\n /**\n * Load all the entries by their ID\n */\n const promises = models.map(model => {\n return context.cms.getEntriesByIds(model, referencesByModel[model.modelId]);\n });\n\n const results = await Promise.all(promises);\n\n const records: Record<string, CmsRefEntry> = results.reduce((collection, entries) => {\n for (const entry of entries) {\n collection[entry.id] = {\n id: entry.id,\n entryId: entry.entryId,\n modelId: entry.modelId\n };\n }\n return collection;\n }, {} as Record<string, CmsRefEntry>);\n /**\n * Verify that all referenced entries actually exist.\n */\n for (const modelId in referencesByModel) {\n const entries = referencesByModel[modelId];\n for (const id of entries) {\n if (records[id]) {\n continue;\n } else if (validateEntries === true) {\n throw new WebinyError(\n `Missing referenced entry with id \"${id}\" in model \"${modelId}\".`,\n \"ENTRY_NOT_FOUND\",\n {\n id,\n model: modelId\n }\n );\n }\n const { id: entryId } = parseIdentifier(id);\n records[id] = {\n id,\n entryId,\n modelId\n };\n }\n }\n\n /**\n * In the end, assign the entryId, id and model values to the output.\n */\n for (const id in pathsByReferenceId) {\n const entry = records[id];\n const paths = pathsByReferenceId[id];\n if (!entry) {\n if (validateEntries === true) {\n throw new WebinyError(\"Missing entry in records.\", \"ENTRY_ERROR\", {\n id,\n paths\n });\n }\n continue;\n }\n for (const path of paths) {\n output = dotProp.set(output, path, {\n id: entry.id,\n entryId: entry.entryId,\n modelId: entry.modelId\n });\n }\n }\n\n return output;\n};\n"],"mappings":";;;;;;;;;;;AACA;;AACA;;AACA;;AA0BA,MAAMA,wBAAwB,GAAIC,MAAD,IAAgD;EAC7E,MAAM;IAAEC,MAAF;IAAUC,WAAW,EAAEC,kBAAvB;IAA2CC;EAA3C,IAAqDJ,MAA3D;EAEA,MAAME,WAAW,GAAG,CAAC,GAAGC,kBAAJ,CAApB;EAEA,MAAME,gBAAgB,GAAGC,KAAK,CAACC,OAAN,CAAcH,KAAd,CAAzB;EAEA,OAAOH,MAAM,CACRO,MADE,CACKC,KAAK,IAAI,CAAC,QAAD,EAAW,KAAX,EAAkBC,QAAlB,CAA2BD,KAAK,CAACE,IAAjC,CADd,EAEFC,MAFE,CAEK,CAACC,UAAD,EAAaJ,KAAb,KAAuB;IAAA;;IAC3B;AACZ;AACA;IACY,IAAIA,KAAK,CAAC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EAA4D;UAC9DzB,EAD8D;UAE9D2B;QAF8D,CAA5D,CAAN;MAIH;;MACD;IACH;;IACD,KAAK,MAAMrC,IAAX,IAAmBqC,KAAnB,EAA0B;MACtBnB,MAAM,GAAGtB,gBAAA,CAAQ0C,GAAR,CAAYpB,MAAZ,EAAoBlB,IAApB,EAA0B;QAC/BU,EAAE,EAAEwB,KAAK,CAACxB,EADqB;QAE/BE,OAAO,EAAEsB,KAAK,CAACtB,OAFgB;QAG/BD,OAAO,EAAEuB,KAAK,CAACvB;MAHgB,CAA1B,CAAT;IAKH;EACJ;;EAED,OAAOO,MAAP;AACH,CAnIM"}
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_dotProp","_utils","_getBaseFieldType","buildReferenceFieldPaths","params","fields","parentPaths","initialParentPaths","input","isMultipleValues","Array","isArray","filter","field","includes","getBaseFieldType","reduce","collection","baseType","parentPathsValue","length","join","multipleValues","inputValue","dotProp","get","fieldId","key","path","push","templates","settings","values","forEach","value","index","valueTemplate","Object","keys","template","find","tpl","gqlTypeName","result","concat","String","objFieldPath","objFieldInputValue","results","getReferenceFieldValue","ref","id","modelId","entryId","trim","referenceFieldsMapping","context","model","validateEntries","output","referenceFieldPaths","validateReferencedEntries","refValue","maybeEntryId","parseIdentifier","set","exports","referencesByModel","Map","has","size","models","security","withoutAuthorization","cms","listModels","entries","promises","map","getEntriesByIds","allEntries","Promise","all","then","res","flat","entriesByModel","acc","entry","ids","modelEntriesInDb","WebinyError"],"sources":["referenceFieldsMapping.ts"],"sourcesContent":["import { CmsContext, CmsDynamicZoneTemplate, CmsModel, CmsModelField } from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport dotProp from \"dot-prop\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\n\ninterface CmsRefEntry {\n id: string;\n entryId: string;\n modelId: string;\n}\n\ntype RefValue = Pick<CmsRefEntry, \"id\" | \"modelId\"> & {\n entryId?: string;\n};\n\ninterface ReferenceObject {\n id: string;\n modelId: string;\n}\n\ninterface Params {\n context: CmsContext;\n model: CmsModel;\n input: Record<string, ReferenceObject | ReferenceObject[]>;\n validateEntries?: boolean;\n}\n\ninterface BuildReferenceFieldPaths {\n fields: CmsModelField[];\n parentPaths: string[];\n input: Record<string, any>;\n}\n\nconst buildReferenceFieldPaths = (params: BuildReferenceFieldPaths): string[] => {\n const { fields, parentPaths: initialParentPaths, input } = params;\n\n const parentPaths = [...initialParentPaths];\n\n const isMultipleValues = Array.isArray(input);\n\n return fields\n .filter(field => [\"object\", \"ref\", \"dynamicZone\"].includes(getBaseFieldType(field)))\n .reduce((collection, field) => {\n /**\n * First we check the ref field\n */\n const baseType = getBaseFieldType(field);\n if (baseType === \"ref\") {\n const parentPathsValue = parentPaths.length > 0 ? `${parentPaths.join(\".\")}.` : \"\";\n if (field.multipleValues) {\n const inputValue = dotProp.get(input, `${field.fieldId}`, []);\n if (!Array.isArray(inputValue)) {\n return collection;\n }\n\n for (const key in inputValue) {\n const path = `${parentPathsValue}${field.fieldId}.${key}`;\n collection.push(path);\n }\n return collection;\n }\n\n if (isMultipleValues) {\n for (const key in input) {\n const path = `${parentPathsValue}${key}.${field.fieldId}`;\n collection.push(path);\n }\n return collection;\n }\n\n collection.push(`${parentPathsValue}${field.fieldId}`);\n\n return collection;\n }\n\n if (baseType === \"dynamicZone\") {\n const templates: CmsDynamicZoneTemplate[] = field.settings?.templates || [];\n\n if (field.multipleValues) {\n const values = dotProp.get(input, field.fieldId, []);\n if (!Array.isArray(values)) {\n return collection;\n }\n\n values.forEach((value, index) => {\n const valueTemplate = Object.keys(value)[0];\n const template = templates.find(tpl => tpl.gqlTypeName === valueTemplate);\n if (!template) {\n return;\n }\n\n const result = buildReferenceFieldPaths({\n fields: template.fields,\n input: value[valueTemplate],\n parentPaths: parentPaths.concat([\n field.fieldId,\n String(index),\n template.gqlTypeName\n ])\n });\n\n collection.push(...result);\n });\n\n return collection;\n }\n\n const value = dotProp.get(input, field.fieldId, {});\n if (!value) {\n return collection;\n }\n\n const valueTemplate = Object.keys(value)[0];\n const template = templates.find(tpl => tpl.gqlTypeName === valueTemplate);\n\n if (!template) {\n return collection;\n }\n\n const result = buildReferenceFieldPaths({\n fields: template.fields,\n input: dotProp.get(value, valueTemplate, {}),\n parentPaths: parentPaths.concat([field.fieldId, template.gqlTypeName])\n });\n collection.push(...result);\n\n return collection;\n }\n\n /**\n * Then we move onto the object field\n */\n const parentPathsValue = parentPaths.length > 0 ? `${parentPaths.join(\".\")}.` : \"\";\n /**\n * This is if received input is array. We need to map key with fieldId at this point.\n */\n if (isMultipleValues) {\n for (const key in input) {\n const path = `${parentPathsValue}${key}.${field.fieldId}`;\n collection.push(path);\n }\n return collection;\n }\n\n const objFieldPath = `${field.fieldId}`;\n const objFieldInputValue = dotProp.get(input, objFieldPath, []);\n\n /**\n * If field is multiple values one, we need to go through the input and use the existing keys.\n */\n if (field.multipleValues) {\n if (Array.isArray(objFieldInputValue) === false) {\n return collection;\n }\n for (const key in objFieldInputValue) {\n const result = buildReferenceFieldPaths({\n fields: field.settings?.fields || [],\n input: objFieldInputValue[key],\n parentPaths: parentPaths.concat([field.fieldId, key])\n });\n collection.push(...result);\n }\n\n return collection;\n }\n\n /**\n * Single value reference field.\n */\n const results = buildReferenceFieldPaths({\n fields: field.settings?.fields || [],\n input: objFieldInputValue,\n parentPaths: parentPaths.concat([field.fieldId])\n });\n\n return collection.concat(results);\n }, [] as string[]);\n};\n\nconst getReferenceFieldValue = (ref: any): { id: string | null; modelId: string | null } => {\n if (!ref) {\n return {\n id: null,\n modelId: null\n };\n }\n return {\n id: (ref.id || ref.entryId || \"\").trim() || null,\n modelId: (ref.modelId || \"\").trim() || null\n };\n};\n\n/**\n * This function traverses the content entry input value, extracts all occurrences of the `ref` field,\n * optionally verifies that those referenced entries exist (by loading them), and normalizes the `ref` value to\n * always contain `{ id, modelId, entryId }`. `entryId` is important when data is being loaded via\n * the `read` and `preview` endpoint.\n */\nexport const referenceFieldsMapping = async (params: Params): Promise<Record<string, any>> => {\n const { context, model, input, validateEntries = false } = params;\n\n let output: Record<string, any> = {\n ...input\n };\n\n const referenceFieldPaths = buildReferenceFieldPaths({\n fields: model.fields,\n input,\n parentPaths: []\n });\n\n if (!referenceFieldPaths.length) {\n return output;\n }\n\n if (validateEntries) {\n await validateReferencedEntries({ output, context, referenceFieldPaths });\n }\n\n /**\n * Assign the entryId, id and model values to the output.\n */\n for (const path of referenceFieldPaths) {\n // It is safe to cast here, because `referenceFieldPaths` array is generated from the `input`.\n const refValue: RefValue | undefined = dotProp.get(input, path);\n if (!refValue) {\n continue;\n }\n\n /**\n * Over time, the structure of `RefInput` was changing, and we need to handle different cases for backwards\n * compatibility. The latest valid structure of a `ref` field value is { id, modelId }, but we also need\n * to make sure that the legacy structure { entryId, modelId } is supported.\n */\n const { id, modelId, entryId: maybeEntryId } = refValue;\n\n const { id: entryId } = parseIdentifier(maybeEntryId || id);\n\n output = dotProp.set(output, path, {\n // If `id` is not set, we're dealing with the legacy structure.\n id: id ?? maybeEntryId,\n entryId,\n modelId\n });\n }\n\n return output;\n};\n\ninterface ValidateReferencedEntriesParams {\n output: Record<string, any>;\n context: CmsContext;\n referenceFieldPaths: string[];\n}\n\nasync function validateReferencedEntries({\n output,\n context,\n referenceFieldPaths\n}: ValidateReferencedEntriesParams) {\n const referencesByModel = new Map<string, string[]>();\n\n /**\n * Group references by modelId.\n */\n for (const path of referenceFieldPaths) {\n const ref = dotProp.get(output, path) as ReferenceObject | any;\n\n const { id, modelId } = getReferenceFieldValue(ref);\n\n if (!id || !modelId) {\n continue;\n }\n\n if (!referencesByModel.has(modelId)) {\n referencesByModel.set(modelId, []);\n }\n\n referencesByModel.get(modelId)?.push(id);\n }\n\n if (!referencesByModel.size) {\n return;\n }\n\n /**\n * Load all models and use only those that are used in reference.\n */\n const models = await context.security.withoutAuthorization(async () => {\n return (await context.cms.listModels()).filter(model => {\n const entries = referencesByModel.get(model.modelId);\n if (!Array.isArray(entries) || entries.length === 0) {\n return false;\n }\n return true;\n });\n });\n\n if (!models.length) {\n return;\n }\n\n /**\n * Load all the entries by their IDs.\n */\n const promises = await context.security.withoutAuthorization(async () => {\n return models.map(model => {\n return context.cms.getEntriesByIds(model, referencesByModel.get(model.modelId) || []);\n });\n });\n\n const allEntries = await Promise.all(promises).then(res => res.flat());\n const entriesByModel = allEntries.reduce<Record<string, string[]>>((acc, entry) => {\n return { ...acc, [entry.modelId]: [...(acc[entry.modelId] || []), entry.id] };\n }, {});\n\n /**\n * Verify that all entries exist.\n */\n referencesByModel.forEach((ids, modelId) => {\n const modelEntriesInDb = entriesByModel[modelId];\n for (const id of ids) {\n if (!modelEntriesInDb.includes(id)) {\n throw new WebinyError(\n `Missing referenced entry with id \"${id}\" in model \"${modelId}\".`,\n \"ENTRY_NOT_FOUND\",\n {\n id,\n model: modelId\n }\n );\n }\n }\n });\n}\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AA8BA,MAAMI,wBAAwB,GAAIC,MAAgC,IAAe;EAC7E,MAAM;IAAEC,MAAM;IAAEC,WAAW,EAAEC,kBAAkB;IAAEC;EAAM,CAAC,GAAGJ,MAAM;EAEjE,MAAME,WAAW,GAAG,CAAC,GAAGC,kBAAkB,CAAC;EAE3C,MAAME,gBAAgB,GAAGC,KAAK,CAACC,OAAO,CAACH,KAAK,CAAC;EAE7C,OAAOH,MAAM,CACRO,MAAM,CAACC,KAAK,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,aAAa,CAAC,CAACC,QAAQ,CAAC,IAAAC,kCAAgB,EAACF,KAAK,CAAC,CAAC,CAAC,CACnFG,MAAM,CAAC,CAACC,UAAU,EAAEJ,KAAK,KAAK;IAC3B;AACZ;AACA;IACY,MAA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AC;EAEF,MAAM4B,UAAU,GAAG,MAAMC,OAAO,CAACC,GAAG,CAACL,QAAQ,CAAC,CAACM,IAAI,CAACC,GAAG,IAAIA,GAAG,CAACC,IAAI,CAAC,CAAC,CAAC;EACtE,MAAMC,cAAc,GAAGN,UAAU,CAAChE,MAAM,CAA2B,CAACuE,GAAG,EAAEC,KAAK,KAAK;IAC/E,OAAO;MAAE,GAAGD,GAAG;MAAE,CAACC,KAAK,CAACpC,OAAO,GAAG,CAAC,IAAImC,GAAG,CAACC,KAAK,CAACpC,OAAO,CAAC,IAAI,EAAE,CAAC,EAAEoC,KAAK,CAACrC,EAAE;IAAE,CAAC;EACjF,CAAC,EAAE,CAAC,CAAC,CAAC;;EAEN;AACJ;AACA;EACIgB,iBAAiB,CAAClC,OAAO,CAAC,CAACwD,GAAG,EAAErC,OAAO,KAAK;IACxC,MAAMsC,gBAAgB,GAAGJ,cAAc,CAAClC,OAAO,CAAC;IAChD,KAAK,MAAMD,EAAE,IAAIsC,GAAG,EAAE;MAClB,IAAI,CAACC,gBAAgB,CAAC5E,QAAQ,CAACqC,EAAE,CAAC,EAAE;QAChC,MAAM,IAAIwC,cAAW,CAChB,qCAAoCxC,EAAG,eAAcC,OAAQ,IAAG,EACjE,iBAAiB,EACjB;UACID,EAAE;UACFM,KAAK,EAAEL;QACX,CACJ,CAAC;MACL;IACJ;EACJ,CAAC,CAAC;AACN"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CmsModelField } from "../../types";
|
|
2
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
3
|
+
interface Params {
|
|
4
|
+
input: string[];
|
|
5
|
+
fields: CmsModelField[];
|
|
6
|
+
plugins: PluginsContainer;
|
|
7
|
+
}
|
|
8
|
+
export declare const getSearchableFields: (params: Params) => string[];
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSearchableFields = void 0;
|
|
7
|
+
const buildSearchableFieldList = params => {
|
|
8
|
+
const {
|
|
9
|
+
input,
|
|
10
|
+
plugins,
|
|
11
|
+
fields,
|
|
12
|
+
parents
|
|
13
|
+
} = params;
|
|
14
|
+
return fields.reduce((result, field) => {
|
|
15
|
+
/**
|
|
16
|
+
* We need to check if the field is full text searchable, and for that we need a plugin for the field type.
|
|
17
|
+
*/
|
|
18
|
+
const plugin = plugins[field.type];
|
|
19
|
+
if (!plugin) {
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* There is a possibility that searchable fields exist in nested object field, so check that as well.
|
|
24
|
+
*/
|
|
25
|
+
const childFields = field.settings?.fields || [];
|
|
26
|
+
if (childFields.length > 0) {
|
|
27
|
+
/**
|
|
28
|
+
* So we build a list of searchable child fields and push it into the main result set.
|
|
29
|
+
*/
|
|
30
|
+
const childResults = buildSearchableFieldList({
|
|
31
|
+
fields: childFields,
|
|
32
|
+
parents: [...parents, field.fieldId],
|
|
33
|
+
plugins,
|
|
34
|
+
input
|
|
35
|
+
});
|
|
36
|
+
result.push(...childResults);
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* If not searchable, continue further.
|
|
41
|
+
*/
|
|
42
|
+
if (!plugin.fullTextSearch || field.settings?.disableFullTextSearch === true) {
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Combine all parent paths with the current one and push it.
|
|
48
|
+
*/
|
|
49
|
+
const path = [...parents, field.fieldId].join(".");
|
|
50
|
+
result.push(path);
|
|
51
|
+
return result;
|
|
52
|
+
}, []);
|
|
53
|
+
};
|
|
54
|
+
const getSearchableFields = params => {
|
|
55
|
+
const {
|
|
56
|
+
plugins,
|
|
57
|
+
input,
|
|
58
|
+
fields
|
|
59
|
+
} = params;
|
|
60
|
+
const fieldPluginMap = plugins.byType("cms-model-field-to-graphql").reduce((collection, field) => {
|
|
61
|
+
collection[field.fieldType] = field;
|
|
62
|
+
return collection;
|
|
63
|
+
}, {});
|
|
64
|
+
return buildSearchableFieldList({
|
|
65
|
+
fields,
|
|
66
|
+
input,
|
|
67
|
+
plugins: fieldPluginMap,
|
|
68
|
+
parents: []
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
exports.getSearchableFields = getSearchableFields;
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=searchableFields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["buildSearchableFieldList","params","input","plugins","fields","parents","reduce","result","field","plugin","type","childFields","settings","length","childResults","fieldId","push","fullTextSearch","disableFullTextSearch","path","join","getSearchableFields","fieldPluginMap","byType","collection","fieldType","exports"],"sources":["searchableFields.ts"],"sourcesContent":["import { CmsModelField, CmsModelFieldToGraphQLPlugin } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\ninterface BuildParams {\n input: string[];\n fields: CmsModelField[];\n plugins: Record<string, CmsModelFieldToGraphQLPlugin>;\n parents: string[];\n}\nconst buildSearchableFieldList = (params: BuildParams): string[] => {\n const { input, plugins, fields, parents } = params;\n return fields.reduce<string[]>((result, field) => {\n /**\n * We need to check if the field is full text searchable, and for that we need a plugin for the field type.\n */\n const plugin = plugins[field.type];\n if (!plugin) {\n return result;\n }\n /**\n * There is a possibility that searchable fields exist in nested object field, so check that as well.\n */\n const childFields = field.settings?.fields || [];\n if (childFields.length > 0) {\n /**\n * So we build a list of searchable child fields and push it into the main result set.\n */\n const childResults = buildSearchableFieldList({\n fields: childFields,\n parents: [...parents, field.fieldId],\n plugins,\n input\n });\n\n result.push(...childResults);\n return result;\n }\n /**\n * If not searchable, continue further.\n */\n if (!plugin.fullTextSearch || field.settings?.disableFullTextSearch === true) {\n return result;\n }\n\n /**\n * Combine all parent paths with the current one and push it.\n */\n const path = [...parents, field.fieldId].join(\".\");\n result.push(path);\n\n return result;\n }, []);\n};\n\ninterface Params {\n input: string[];\n fields: CmsModelField[];\n plugins: PluginsContainer;\n}\nexport const getSearchableFields = (params: Params): string[] => {\n const { plugins, input, fields } = params;\n const fieldPluginMap = plugins\n .byType<CmsModelFieldToGraphQLPlugin>(\"cms-model-field-to-graphql\")\n .reduce((collection, field) => {\n collection[field.fieldType] = field;\n return collection;\n }, {} as Record<string, CmsModelFieldToGraphQLPlugin>);\n\n return buildSearchableFieldList({\n fields,\n input,\n plugins: fieldPluginMap,\n parents: []\n });\n};\n"],"mappings":";;;;;;AASA,MAAMA,wBAAwB,GAAIC,MAAmB,IAAe;EAChE,MAAM;IAAEC,KAAK;IAAEC,OAAO;IAAEC,MAAM;IAAEC;EAAQ,CAAC,GAAGJ,MAAM;EAClD,OAAOG,MAAM,CAACE,MAAM,CAAW,CAACC,MAAM,EAAEC,KAAK,KAAK;IAC9C;AACR;AACA;IACQ,MAAMC,MAAM,GAAGN,OAAO,CAACK,KAAK,CAACE,IAAI,CAAC;IAClC,IAAI,CAACD,MAAM,EAAE;MACT,OAAOF,MAAM;IACjB;IACA;AACR;AACA;IACQ,MAAMI,WAAW,GAAGH,KAAK,CAACI,QAAQ,EAAER,MAAM,IAAI,EAAE;IAChD,IAAIO,WAAW,CAACE,MAAM,GAAG,CAAC,EAAE;MACxB;AACZ;AACA;MACY,MAAMC,YAAY,GAAGd,wBAAwB,CAAC;QAC1CI,MAAM,EAAEO,WAAW;QACnBN,OAAO,EAAE,CAAC,GAAGA,OAAO,EAAEG,KAAK,CAACO,OAAO,CAAC;QACpCZ,OAAO;QACPD;MACJ,CAAC,CAAC;MAEFK,MAAM,CAACS,IAAI,CAAC,GAAGF,YAAY,CAAC;MAC5B,OAAOP,MAAM;IACjB;IACA;AACR;AACA;IACQ,IAAI,CAACE,MAAM,CAACQ,cAAc,IAAIT,KAAK,CAACI,QAAQ,EAAEM,qBAAqB,KAAK,IAAI,EAAE;MAC1E,OAAOX,MAAM;IACjB;;IAEA;AACR;AACA;IACQ,MAAMY,IAAI,GAAG,CAAC,GAAGd,OAAO,EAAEG,KAAK,CAACO,OAAO,CAAC,CAACK,IAAI,CAAC,GAAG,CAAC;IAClDb,MAAM,CAACS,IAAI,CAACG,IAAI,CAAC;IAEjB,OAAOZ,MAAM;EACjB,CAAC,EAAE,EAAE,CAAC;AACV,CAAC;AAOM,MAAMc,mBAAmB,GAAIpB,MAAc,IAAe;EAC7D,MAAM;IAAEE,OAAO;IAAED,KAAK;IAAEE;EAAO,CAAC,GAAGH,MAAM;EACzC,MAAMqB,cAAc,GAAGnB,OAAO,CACzBoB,MAAM,CAA+B,4BAA4B,CAAC,CAClEjB,MAAM,CAAC,CAACkB,UAAU,EAAEhB,KAAK,KAAK;IAC3BgB,UAAU,CAAChB,KAAK,CAACiB,SAAS,CAAC,GAAGjB,KAAK;IACnC,OAAOgB,UAAU;EACrB,CAAC,EAAE,CAAC,CAAiD,CAAC;EAE1D,OAAOxB,wBAAwB,CAAC;IAC5BI,MAAM;IACNF,KAAK;IACLC,OAAO,EAAEmB,cAAc;IACvBjB,OAAO,EAAE;EACb,CAAC,CAAC;AACN,CAAC;AAACqB,OAAA,CAAAL,mBAAA,GAAAA,mBAAA"}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CmsContext, CmsEntryContext, HeadlessCmsStorageOperations } from "../types";
|
|
2
2
|
import { SecurityIdentity } from "@webiny/api-security/types";
|
|
3
3
|
import { Tenant } from "@webiny/api-tenancy/types";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import { I18NLocale } from "@webiny/api-i18n/types";
|
|
5
|
+
import { EntriesPermissions } from "../utils/permissions/EntriesPermissions";
|
|
6
|
+
import { ModelsPermissions } from "../utils/permissions/ModelsPermissions";
|
|
7
|
+
interface CreateContentEntryCrudParams {
|
|
8
8
|
storageOperations: HeadlessCmsStorageOperations;
|
|
9
|
+
entriesPermissions: EntriesPermissions;
|
|
10
|
+
modelsPermissions: ModelsPermissions;
|
|
9
11
|
context: CmsContext;
|
|
10
12
|
getIdentity: () => SecurityIdentity;
|
|
11
13
|
getTenant: () => Tenant;
|
|
14
|
+
getLocale: () => I18NLocale;
|
|
12
15
|
}
|
|
13
16
|
export declare const createContentEntryCrud: (params: CreateContentEntryCrudParams) => CmsEntryContext;
|
|
17
|
+
export {};
|