@webiny/api-headless-cms 0.0.0-ee-vpcs.549378cf03
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/LICENSE +21 -0
- package/README.md +73 -0
- package/context.d.ts +3 -0
- package/context.js +60 -0
- package/context.js.map +1 -0
- package/crud/contentEntry/afterDelete.d.ts +8 -0
- package/crud/contentEntry/afterDelete.js +41 -0
- package/crud/contentEntry/afterDelete.js.map +1 -0
- package/crud/contentEntry/beforeCreate.d.ts +8 -0
- package/crud/contentEntry/beforeCreate.js +28 -0
- package/crud/contentEntry/beforeCreate.js.map +1 -0
- package/crud/contentEntry/beforeUpdate.d.ts +8 -0
- package/crud/contentEntry/beforeUpdate.js +28 -0
- package/crud/contentEntry/beforeUpdate.js.map +1 -0
- package/crud/contentEntry/entryDataValidation.d.ts +10 -0
- package/crud/contentEntry/entryDataValidation.js +200 -0
- package/crud/contentEntry/entryDataValidation.js.map +1 -0
- package/crud/contentEntry/markLockedFields.d.ts +13 -0
- package/crud/contentEntry/markLockedFields.js +116 -0
- package/crud/contentEntry/markLockedFields.js.map +1 -0
- package/crud/contentEntry/referenceFieldsMapping.d.ts +13 -0
- package/crud/contentEntry/referenceFieldsMapping.js +292 -0
- package/crud/contentEntry/referenceFieldsMapping.js.map +1 -0
- package/crud/contentEntry/searchableFields.d.ts +9 -0
- package/crud/contentEntry/searchableFields.js +83 -0
- package/crud/contentEntry/searchableFields.js.map +1 -0
- package/crud/contentEntry.crud.d.ts +13 -0
- package/crud/contentEntry.crud.js +1277 -0
- package/crud/contentEntry.crud.js.map +1 -0
- package/crud/contentModel/afterCreate.d.ts +8 -0
- package/crud/contentModel/afterCreate.js +18 -0
- package/crud/contentModel/afterCreate.js.map +1 -0
- package/crud/contentModel/afterCreateFrom.d.ts +8 -0
- package/crud/contentModel/afterCreateFrom.js +18 -0
- package/crud/contentModel/afterCreateFrom.js.map +1 -0
- package/crud/contentModel/afterDelete.d.ts +8 -0
- package/crud/contentModel/afterDelete.js +18 -0
- package/crud/contentModel/afterDelete.js.map +1 -0
- package/crud/contentModel/afterUpdate.d.ts +8 -0
- package/crud/contentModel/afterUpdate.js +18 -0
- package/crud/contentModel/afterUpdate.js.map +1 -0
- package/crud/contentModel/beforeCreate.d.ts +15 -0
- package/crud/contentModel/beforeCreate.js +194 -0
- package/crud/contentModel/beforeCreate.js.map +1 -0
- package/crud/contentModel/beforeDelete.d.ts +10 -0
- package/crud/contentModel/beforeDelete.js +60 -0
- package/crud/contentModel/beforeDelete.js.map +1 -0
- package/crud/contentModel/beforeUpdate.d.ts +10 -0
- package/crud/contentModel/beforeUpdate.js +37 -0
- package/crud/contentModel/beforeUpdate.js.map +1 -0
- package/crud/contentModel/contentModelManagerFactory.d.ts +2 -0
- package/crud/contentModel/contentModelManagerFactory.js +29 -0
- package/crud/contentModel/contentModelManagerFactory.js.map +1 -0
- package/crud/contentModel/createFieldModels.d.ts +2 -0
- package/crud/contentModel/createFieldModels.js +26 -0
- package/crud/contentModel/createFieldModels.js.map +1 -0
- package/crud/contentModel/createFieldStorageId.d.ts +2 -0
- package/crud/contentModel/createFieldStorageId.js +20 -0
- package/crud/contentModel/createFieldStorageId.js.map +1 -0
- package/crud/contentModel/fieldIdValidation.d.ts +1 -0
- package/crud/contentModel/fieldIdValidation.js +25 -0
- package/crud/contentModel/fieldIdValidation.js.map +1 -0
- package/crud/contentModel/idValidation.d.ts +1 -0
- package/crud/contentModel/idValidation.js +22 -0
- package/crud/contentModel/idValidation.js.map +1 -0
- package/crud/contentModel/models.d.ts +4 -0
- package/crud/contentModel/models.js +192 -0
- package/crud/contentModel/models.js.map +1 -0
- package/crud/contentModel/systemFields.d.ts +1 -0
- package/crud/contentModel/systemFields.js +8 -0
- package/crud/contentModel/systemFields.js.map +1 -0
- package/crud/contentModel/validateLayout.d.ts +2 -0
- package/crud/contentModel/validateLayout.js +36 -0
- package/crud/contentModel/validateLayout.js.map +1 -0
- package/crud/contentModel/validateModel.d.ts +9 -0
- package/crud/contentModel/validateModel.js +32 -0
- package/crud/contentModel/validateModel.js.map +1 -0
- package/crud/contentModel/validateModelFields.d.ts +9 -0
- package/crud/contentModel/validateModelFields.js +371 -0
- package/crud/contentModel/validateModelFields.js.map +1 -0
- package/crud/contentModel.crud.d.ts +12 -0
- package/crud/contentModel.crud.js +650 -0
- package/crud/contentModel.crud.js.map +1 -0
- package/crud/contentModelGroup/beforeCreate.d.ts +10 -0
- package/crud/contentModelGroup/beforeCreate.js +66 -0
- package/crud/contentModelGroup/beforeCreate.js.map +1 -0
- package/crud/contentModelGroup/beforeDelete.d.ts +10 -0
- package/crud/contentModelGroup/beforeDelete.js +48 -0
- package/crud/contentModelGroup/beforeDelete.js.map +1 -0
- package/crud/contentModelGroup/beforeUpdate.d.ts +9 -0
- package/crud/contentModelGroup/beforeUpdate.js +28 -0
- package/crud/contentModelGroup/beforeUpdate.js.map +1 -0
- package/crud/contentModelGroup.crud.d.ts +12 -0
- package/crud/contentModelGroup.crud.js +396 -0
- package/crud/contentModelGroup.crud.js.map +1 -0
- package/crud/index.d.ts +6 -0
- package/crud/index.js +85 -0
- package/crud/index.js.map +1 -0
- package/crud/settings.crud.d.ts +10 -0
- package/crud/settings.crud.js +83 -0
- package/crud/settings.crud.js.map +1 -0
- package/crud/system.crud.d.ts +13 -0
- package/crud/system.crud.js +221 -0
- package/crud/system.crud.js.map +1 -0
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.d.ts +7 -0
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +66 -0
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js.map +1 -0
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.d.ts +11 -0
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +239 -0
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -0
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.d.ts +11 -0
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +304 -0
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -0
- package/fieldConverters/index.d.ts +4 -0
- package/fieldConverters/index.js +18 -0
- package/fieldConverters/index.js.map +1 -0
- package/graphql/buildSchemaPlugins.d.ts +6 -0
- package/graphql/buildSchemaPlugins.js +27 -0
- package/graphql/buildSchemaPlugins.js.map +1 -0
- package/graphql/graphQLHandlerFactory.d.ts +5 -0
- package/graphql/graphQLHandlerFactory.js +202 -0
- package/graphql/graphQLHandlerFactory.js.map +1 -0
- package/graphql/index.d.ts +5 -0
- package/graphql/index.js +57 -0
- package/graphql/index.js.map +1 -0
- package/graphql/schema/baseContentSchema.d.ts +3 -0
- package/graphql/schema/baseContentSchema.js +76 -0
- package/graphql/schema/baseContentSchema.js.map +1 -0
- package/graphql/schema/contentEntries.d.ts +3 -0
- package/graphql/schema/contentEntries.js +351 -0
- package/graphql/schema/contentEntries.js.map +1 -0
- package/graphql/schema/contentModelGroups.d.ts +3 -0
- package/graphql/schema/contentModelGroups.js +172 -0
- package/graphql/schema/contentModelGroups.js.map +1 -0
- package/graphql/schema/contentModels.d.ts +3 -0
- package/graphql/schema/contentModels.js +300 -0
- package/graphql/schema/contentModels.js.map +1 -0
- package/graphql/schema/createFieldResolvers.d.ts +20 -0
- package/graphql/schema/createFieldResolvers.js +121 -0
- package/graphql/schema/createFieldResolvers.js.map +1 -0
- package/graphql/schema/createManageResolvers.d.ts +12 -0
- package/graphql/schema/createManageResolvers.js +137 -0
- package/graphql/schema/createManageResolvers.js.map +1 -0
- package/graphql/schema/createManageSDL.d.ts +10 -0
- package/graphql/schema/createManageSDL.js +161 -0
- package/graphql/schema/createManageSDL.js.map +1 -0
- package/graphql/schema/createPreviewResolvers.d.ts +12 -0
- package/graphql/schema/createPreviewResolvers.js +58 -0
- package/graphql/schema/createPreviewResolvers.js.map +1 -0
- package/graphql/schema/createReadResolvers.d.ts +12 -0
- package/graphql/schema/createReadResolvers.js +58 -0
- package/graphql/schema/createReadResolvers.js.map +1 -0
- package/graphql/schema/createReadSDL.d.ts +10 -0
- package/graphql/schema/createReadSDL.js +104 -0
- package/graphql/schema/createReadSDL.js.map +1 -0
- package/graphql/schema/resolvers/commonFieldResolvers.d.ts +6 -0
- package/graphql/schema/resolvers/commonFieldResolvers.js +14 -0
- package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -0
- package/graphql/schema/resolvers/manage/resolveCreate.d.ts +7 -0
- package/graphql/schema/resolvers/manage/resolveCreate.js +21 -0
- package/graphql/schema/resolvers/manage/resolveCreate.js.map +1 -0
- package/graphql/schema/resolvers/manage/resolveCreateFrom.d.ts +8 -0
- package/graphql/schema/resolvers/manage/resolveCreateFrom.js +21 -0
- package/graphql/schema/resolvers/manage/resolveCreateFrom.js.map +1 -0
- package/graphql/schema/resolvers/manage/resolveDelete.d.ts +7 -0
- package/graphql/schema/resolvers/manage/resolveDelete.js +32 -0
- package/graphql/schema/resolvers/manage/resolveDelete.js.map +1 -0
- package/graphql/schema/resolvers/manage/resolveGet.d.ts +7 -0
- package/graphql/schema/resolvers/manage/resolveGet.js +79 -0
- package/graphql/schema/resolvers/manage/resolveGet.js.map +1 -0
- package/graphql/schema/resolvers/manage/resolveGetByIds.d.ts +7 -0
- package/graphql/schema/resolvers/manage/resolveGetByIds.js +21 -0
- package/graphql/schema/resolvers/manage/resolveGetByIds.js.map +1 -0
- package/graphql/schema/resolvers/manage/resolveGetRevisions.d.ts +7 -0
- package/graphql/schema/resolvers/manage/resolveGetRevisions.js +21 -0
- package/graphql/schema/resolvers/manage/resolveGetRevisions.js.map +1 -0
- package/graphql/schema/resolvers/manage/resolveList.d.ts +4 -0
- package/graphql/schema/resolvers/manage/resolveList.js +21 -0
- package/graphql/schema/resolvers/manage/resolveList.js.map +1 -0
- package/graphql/schema/resolvers/manage/resolvePublish.d.ts +7 -0
- package/graphql/schema/resolvers/manage/resolvePublish.js +21 -0
- package/graphql/schema/resolvers/manage/resolvePublish.js.map +1 -0
- package/graphql/schema/resolvers/manage/resolveRepublish.d.ts +7 -0
- package/graphql/schema/resolvers/manage/resolveRepublish.js +21 -0
- package/graphql/schema/resolvers/manage/resolveRepublish.js.map +1 -0
- package/graphql/schema/resolvers/manage/resolveUnpublish.d.ts +7 -0
- package/graphql/schema/resolvers/manage/resolveUnpublish.js +21 -0
- package/graphql/schema/resolvers/manage/resolveUnpublish.js.map +1 -0
- package/graphql/schema/resolvers/manage/resolveUpdate.d.ts +8 -0
- package/graphql/schema/resolvers/manage/resolveUpdate.js +21 -0
- package/graphql/schema/resolvers/manage/resolveUpdate.js.map +1 -0
- package/graphql/schema/resolvers/preview/resolveGet.d.ts +4 -0
- package/graphql/schema/resolvers/preview/resolveGet.js +34 -0
- package/graphql/schema/resolvers/preview/resolveGet.js.map +1 -0
- package/graphql/schema/resolvers/preview/resolveList.d.ts +4 -0
- package/graphql/schema/resolvers/preview/resolveList.js +21 -0
- package/graphql/schema/resolvers/preview/resolveList.js.map +1 -0
- package/graphql/schema/resolvers/read/resolveGet.d.ts +4 -0
- package/graphql/schema/resolvers/read/resolveGet.js +34 -0
- package/graphql/schema/resolvers/read/resolveGet.js.map +1 -0
- package/graphql/schema/resolvers/read/resolveList.d.ts +4 -0
- package/graphql/schema/resolvers/read/resolveList.js +21 -0
- package/graphql/schema/resolvers/read/resolveList.js.map +1 -0
- package/graphql/schema/schemaPlugins.d.ts +3 -0
- package/graphql/schema/schemaPlugins.js +111 -0
- package/graphql/schema/schemaPlugins.js.map +1 -0
- package/graphql/system.d.ts +6 -0
- package/graphql/system.js +119 -0
- package/graphql/system.js.map +1 -0
- package/graphqlFields/boolean.d.ts +2 -0
- package/graphqlFields/boolean.js +69 -0
- package/graphqlFields/boolean.js.map +1 -0
- package/graphqlFields/datetime.d.ts +2 -0
- package/graphqlFields/datetime.js +95 -0
- package/graphqlFields/datetime.js.map +1 -0
- package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +2 -0
- package/graphqlFields/dynamicZone/dynamicZoneField.js +234 -0
- package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.d.ts +3 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js +79 -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.d.ts +2 -0
- package/graphqlFields/file.js +50 -0
- package/graphqlFields/file.js.map +1 -0
- package/graphqlFields/helpers.d.ts +6 -0
- package/graphqlFields/helpers.js +49 -0
- package/graphqlFields/helpers.js.map +1 -0
- package/graphqlFields/index.d.ts +2 -0
- package/graphqlFields/index.js +30 -0
- package/graphqlFields/index.js.map +1 -0
- package/graphqlFields/longText.d.ts +2 -0
- package/graphqlFields/longText.js +63 -0
- package/graphqlFields/longText.js.map +1 -0
- package/graphqlFields/number.d.ts +2 -0
- package/graphqlFields/number.js +79 -0
- package/graphqlFields/number.js.map +1 -0
- package/graphqlFields/object.d.ts +2 -0
- package/graphqlFields/object.js +275 -0
- package/graphqlFields/object.js.map +1 -0
- package/graphqlFields/ref.d.ts +2 -0
- package/graphqlFields/ref.js +257 -0
- package/graphqlFields/ref.js.map +1 -0
- package/graphqlFields/richText.d.ts +2 -0
- package/graphqlFields/richText.js +56 -0
- package/graphqlFields/richText.js.map +1 -0
- package/graphqlFields/text.d.ts +2 -0
- package/graphqlFields/text.js +73 -0
- package/graphqlFields/text.js.map +1 -0
- package/index.d.ts +10 -0
- package/index.js +111 -0
- package/index.js.map +1 -0
- package/modelManager/DefaultCmsModelManager.d.ts +14 -0
- package/modelManager/DefaultCmsModelManager.js +64 -0
- package/modelManager/DefaultCmsModelManager.js.map +1 -0
- package/modelManager/index.d.ts +2 -0
- package/modelManager/index.js +20 -0
- package/modelManager/index.js.map +1 -0
- package/package.json +81 -0
- package/parameters/context.d.ts +2 -0
- package/parameters/context.js +22 -0
- package/parameters/context.js.map +1 -0
- package/parameters/header.d.ts +2 -0
- package/parameters/header.js +55 -0
- package/parameters/header.js.map +1 -0
- package/parameters/index.d.ts +4 -0
- package/parameters/index.js +57 -0
- package/parameters/index.js.map +1 -0
- package/parameters/manual.d.ts +6 -0
- package/parameters/manual.js +44 -0
- package/parameters/manual.js.map +1 -0
- package/parameters/path.d.ts +2 -0
- package/parameters/path.js +51 -0
- package/parameters/path.js.map +1 -0
- package/plugins/CmsGroupPlugin.d.ts +13 -0
- package/plugins/CmsGroupPlugin.js +30 -0
- package/plugins/CmsGroupPlugin.js.map +1 -0
- package/plugins/CmsModelFieldConverterPlugin.d.ts +14 -0
- package/plugins/CmsModelFieldConverterPlugin.js +17 -0
- package/plugins/CmsModelFieldConverterPlugin.js.map +1 -0
- package/plugins/CmsModelPlugin.d.ts +45 -0
- package/plugins/CmsModelPlugin.js +194 -0
- package/plugins/CmsModelPlugin.js.map +1 -0
- package/plugins/CmsParametersPlugin.d.ts +20 -0
- package/plugins/CmsParametersPlugin.js +28 -0
- package/plugins/CmsParametersPlugin.js.map +1 -0
- package/plugins/StorageTransformPlugin.d.ts +31 -0
- package/plugins/StorageTransformPlugin.js +37 -0
- package/plugins/StorageTransformPlugin.js.map +1 -0
- package/plugins/index.d.ts +5 -0
- package/plugins/index.js +70 -0
- package/plugins/index.js.map +1 -0
- package/storage/default.d.ts +2 -0
- package/storage/default.js +27 -0
- package/storage/default.js.map +1 -0
- package/storage/object.d.ts +2 -0
- package/storage/object.js +127 -0
- package/storage/object.js.map +1 -0
- package/types.d.ts +2600 -0
- package/types.js +459 -0
- package/types.js.map +1 -0
- package/upgrades/5.33.0/index.d.ts +3 -0
- package/upgrades/5.33.0/index.js +182 -0
- package/upgrades/5.33.0/index.js.map +1 -0
- package/upgrades/index.d.ts +1 -0
- package/upgrades/index.js +12 -0
- package/upgrades/index.js.map +1 -0
- package/utils/access.d.ts +8 -0
- package/utils/access.js +90 -0
- package/utils/access.js.map +1 -0
- package/utils/converters/Converter.d.ts +27 -0
- package/utils/converters/Converter.js +71 -0
- package/utils/converters/Converter.js.map +1 -0
- package/utils/converters/ConverterCollection.d.ts +31 -0
- package/utils/converters/ConverterCollection.js +143 -0
- package/utils/converters/ConverterCollection.js.map +1 -0
- package/utils/converters/valueKeyStorageConverter.d.ts +18 -0
- package/utils/converters/valueKeyStorageConverter.js +148 -0
- package/utils/converters/valueKeyStorageConverter.js.map +1 -0
- package/utils/createTypeFromFields.d.ts +15 -0
- package/utils/createTypeFromFields.js +75 -0
- package/utils/createTypeFromFields.js.map +1 -0
- package/utils/createTypeName.d.ts +3 -0
- package/utils/createTypeName.js +30 -0
- package/utils/createTypeName.js.map +1 -0
- package/utils/entryStorage.d.ts +17 -0
- package/utils/entryStorage.js +120 -0
- package/utils/entryStorage.js.map +1 -0
- package/utils/filterAsync.d.ts +1 -0
- package/utils/filterAsync.js +23 -0
- package/utils/filterAsync.js.map +1 -0
- package/utils/filterModelFields.d.ts +16 -0
- package/utils/filterModelFields.js +77 -0
- package/utils/filterModelFields.js.map +1 -0
- package/utils/getBaseFieldType.d.ts +4 -0
- package/utils/getBaseFieldType.js +12 -0
- package/utils/getBaseFieldType.js.map +1 -0
- package/utils/getEntryTitle.d.ts +2 -0
- package/utils/getEntryTitle.js +43 -0
- package/utils/getEntryTitle.js.map +1 -0
- package/utils/getSchemaFromFieldPlugins.d.ts +12 -0
- package/utils/getSchemaFromFieldPlugins.js +35 -0
- package/utils/getSchemaFromFieldPlugins.js.map +1 -0
- package/utils/ownership.d.ts +8 -0
- package/utils/ownership.js +41 -0
- package/utils/ownership.js.map +1 -0
- package/utils/permissions.d.ts +7 -0
- package/utils/permissions.js +106 -0
- package/utils/permissions.js.map +1 -0
- package/utils/pluralizedTypeName.d.ts +1 -0
- package/utils/pluralizedTypeName.js +26 -0
- package/utils/pluralizedTypeName.js.map +1 -0
- package/utils/renderFields.d.ts +15 -0
- package/utils/renderFields.js +55 -0
- package/utils/renderFields.js.map +1 -0
- package/utils/renderGetFilterFields.d.ts +10 -0
- package/utils/renderGetFilterFields.js +61 -0
- package/utils/renderGetFilterFields.js.map +1 -0
- package/utils/renderInputFields.d.ts +14 -0
- package/utils/renderInputFields.js +55 -0
- package/utils/renderInputFields.js.map +1 -0
- package/utils/renderListFilterFields.d.ts +11 -0
- package/utils/renderListFilterFields.js +62 -0
- package/utils/renderListFilterFields.js.map +1 -0
- package/utils/renderSortEnum.d.ts +9 -0
- package/utils/renderSortEnum.js +34 -0
- package/utils/renderSortEnum.js.map +1 -0
- package/utils/toSlug.d.ts +1 -0
- package/utils/toSlug.js +20 -0
- package/utils/toSlug.js.map +1 -0
- package/validators/dateGte.d.ts +2 -0
- package/validators/dateGte.js +37 -0
- package/validators/dateGte.js.map +1 -0
- package/validators/dateLte.d.ts +2 -0
- package/validators/dateLte.js +37 -0
- package/validators/dateLte.js.map +1 -0
- package/validators/dynamicZone.d.ts +2 -0
- package/validators/dynamicZone.js +24 -0
- package/validators/dynamicZone.js.map +1 -0
- package/validators/gte.d.ts +2 -0
- package/validators/gte.js +36 -0
- package/validators/gte.js.map +1 -0
- package/validators/in.d.ts +2 -0
- package/validators/in.js +36 -0
- package/validators/in.js.map +1 -0
- package/validators/index.d.ts +1 -0
- package/validators/index.js +38 -0
- package/validators/index.js.map +1 -0
- package/validators/lte.d.ts +2 -0
- package/validators/lte.js +36 -0
- package/validators/lte.js.map +1 -0
- package/validators/maxLength.d.ts +2 -0
- package/validators/maxLength.js +36 -0
- package/validators/maxLength.js.map +1 -0
- package/validators/minLength.d.ts +2 -0
- package/validators/minLength.js +36 -0
- package/validators/minLength.js.map +1 -0
- package/validators/pattern.d.ts +2 -0
- package/validators/pattern.js +50 -0
- package/validators/pattern.js.map +1 -0
- package/validators/patternPlugins/email.d.ts +2 -0
- package/validators/patternPlugins/email.js +20 -0
- package/validators/patternPlugins/email.js.map +1 -0
- package/validators/patternPlugins/index.d.ts +2 -0
- package/validators/patternPlugins/index.js +24 -0
- package/validators/patternPlugins/index.js.map +1 -0
- package/validators/patternPlugins/lowerCase.d.ts +2 -0
- package/validators/patternPlugins/lowerCase.js +20 -0
- package/validators/patternPlugins/lowerCase.js.map +1 -0
- package/validators/patternPlugins/lowerCaseSpace.d.ts +2 -0
- package/validators/patternPlugins/lowerCaseSpace.js +20 -0
- package/validators/patternPlugins/lowerCaseSpace.js.map +1 -0
- package/validators/patternPlugins/upperCase.d.ts +2 -0
- package/validators/patternPlugins/upperCase.js +20 -0
- package/validators/patternPlugins/upperCase.js.map +1 -0
- package/validators/patternPlugins/upperCaseSpace.d.ts +2 -0
- package/validators/patternPlugins/upperCaseSpace.js +20 -0
- package/validators/patternPlugins/upperCaseSpace.js.map +1 -0
- package/validators/patternPlugins/url.d.ts +2 -0
- package/validators/patternPlugins/url.js +20 -0
- package/validators/patternPlugins/url.js.map +1 -0
- package/validators/required.d.ts +2 -0
- package/validators/required.js +27 -0
- package/validators/required.js.map +1 -0
- package/validators/timeGte.d.ts +2 -0
- package/validators/timeGte.js +34 -0
- package/validators/timeGte.js.map +1 -0
- package/validators/timeLte.d.ts +2 -0
- package/validators/timeLte.js +34 -0
- package/validators/timeLte.js.map +1 -0
- package/validators/unique.d.ts +6 -0
- package/validators/unique.js +63 -0
- package/validators/unique.js.map +1 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.markUnlockedFields = exports.markLockedFields = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
14
|
+
var _CmsModelPlugin = require("../../plugins/CmsModelPlugin");
|
|
15
|
+
|
|
16
|
+
var _getBaseFieldType = require("../../utils/getBaseFieldType");
|
|
17
|
+
|
|
18
|
+
const markLockedFields = async params => {
|
|
19
|
+
const {
|
|
20
|
+
model,
|
|
21
|
+
context
|
|
22
|
+
} = params;
|
|
23
|
+
/**
|
|
24
|
+
* If the model is registered via a plugin, we don't need do process anything.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
const plugins = context.plugins.byType(_CmsModelPlugin.CmsModelPlugin.type);
|
|
28
|
+
|
|
29
|
+
if (plugins.find(plugin => plugin.contentModel.modelId === model.modelId)) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const cmsLockedFieldPlugins = context.plugins.byType("cms-model-locked-field");
|
|
34
|
+
const existingLockedFields = model.lockedFields || [];
|
|
35
|
+
const lockedFields = [];
|
|
36
|
+
|
|
37
|
+
for (const field of model.fields) {
|
|
38
|
+
const baseType = (0, _getBaseFieldType.getBaseFieldType)(field);
|
|
39
|
+
const alreadyLocked = existingLockedFields.some(lockedField => lockedField.fieldId === field.storageId);
|
|
40
|
+
|
|
41
|
+
if (alreadyLocked) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let lockedFieldData = {};
|
|
46
|
+
const lockedFieldPlugins = cmsLockedFieldPlugins.filter(pl => pl.fieldType === baseType);
|
|
47
|
+
|
|
48
|
+
for (const plugin of lockedFieldPlugins) {
|
|
49
|
+
if (typeof plugin.getLockedFieldData !== "function") {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const data = plugin.getLockedFieldData({
|
|
54
|
+
field
|
|
55
|
+
});
|
|
56
|
+
lockedFieldData = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, lockedFieldData), data);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
lockedFields.push((0, _objectSpread2.default)({
|
|
60
|
+
fieldId: field.storageId,
|
|
61
|
+
multipleValues: !!field.multipleValues,
|
|
62
|
+
type: baseType
|
|
63
|
+
}, lockedFieldData));
|
|
64
|
+
} // no need to update anything if no locked fields were added
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
if (lockedFields.length === 0) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const newLockedFields = existingLockedFields.concat(lockedFields);
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
await context.cms.updateModelDirect({
|
|
75
|
+
original: model,
|
|
76
|
+
model: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, model), {}, {
|
|
77
|
+
lockedFields: newLockedFields
|
|
78
|
+
})
|
|
79
|
+
});
|
|
80
|
+
model.lockedFields = newLockedFields;
|
|
81
|
+
} catch (ex) {
|
|
82
|
+
throw new _error.default(`Could not update model "${model.modelId}" with new locked fields.`, "MODEL_LOCKED_FIELDS_UPDATE_FAILED", ex);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
exports.markLockedFields = markLockedFields;
|
|
87
|
+
|
|
88
|
+
const markUnlockedFields = async params => {
|
|
89
|
+
const {
|
|
90
|
+
context,
|
|
91
|
+
model
|
|
92
|
+
} = params;
|
|
93
|
+
/**
|
|
94
|
+
* If the model is registered via a plugin, we don't need do process anything.
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
const plugins = context.plugins.byType(_CmsModelPlugin.CmsModelPlugin.type);
|
|
98
|
+
|
|
99
|
+
if (plugins.find(plugin => plugin.contentModel.modelId === model.modelId)) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
await context.cms.updateModelDirect({
|
|
105
|
+
original: model,
|
|
106
|
+
model: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, model), {}, {
|
|
107
|
+
lockedFields: []
|
|
108
|
+
})
|
|
109
|
+
});
|
|
110
|
+
model.lockedFields = [];
|
|
111
|
+
} catch (ex) {
|
|
112
|
+
throw new _error.default(`Could not update model "${model.modelId}" with unlocked fields.`, "MODEL_UNLOCKED_FIELDS_UPDATE_FAILED", ex);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
exports.markUnlockedFields = markUnlockedFields;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["markLockedFields","params","model","context","plugins","byType","CmsModelPlugin","type","find","plugin","contentModel","modelId","cmsLockedFieldPlugins","existingLockedFields","lockedFields","field","fields","baseType","getBaseFieldType","alreadyLocked","some","lockedField","fieldId","storageId","lockedFieldData","lockedFieldPlugins","filter","pl","fieldType","getLockedFieldData","data","push","multipleValues","length","newLockedFields","concat","cms","updateModelDirect","original","ex","WebinyError","markUnlockedFields"],"sources":["markLockedFields.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntry, CmsModel, CmsContext, CmsModelLockedFieldPlugin, LockedField } from \"~/types\";\nimport { CmsModelPlugin } from \"~/plugins/CmsModelPlugin\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\n\ninterface MarkLockedFieldsParams {\n model: CmsModel;\n entry: CmsEntry;\n context: CmsContext;\n}\nexport const markLockedFields = async (params: MarkLockedFieldsParams): Promise<void> => {\n const { model, context } = params;\n /**\n * If the model is registered via a plugin, we don't need do process anything.\n */\n const plugins = context.plugins.byType<CmsModelPlugin>(CmsModelPlugin.type);\n if (plugins.find(plugin => plugin.contentModel.modelId === model.modelId)) {\n return;\n }\n\n const cmsLockedFieldPlugins =\n context.plugins.byType<CmsModelLockedFieldPlugin>(\"cms-model-locked-field\");\n\n const existingLockedFields = model.lockedFields || [];\n const lockedFields: LockedField[] = [];\n for (const field of model.fields) {\n const baseType = getBaseFieldType(field);\n const alreadyLocked = existingLockedFields.some(\n lockedField => lockedField.fieldId === field.storageId\n );\n if (alreadyLocked) {\n continue;\n }\n\n let lockedFieldData = {};\n\n const lockedFieldPlugins = cmsLockedFieldPlugins.filter(pl => pl.fieldType === baseType);\n for (const plugin of lockedFieldPlugins) {\n if (typeof plugin.getLockedFieldData !== \"function\") {\n continue;\n }\n const data = plugin.getLockedFieldData({\n field\n });\n lockedFieldData = { ...lockedFieldData, ...data };\n }\n\n lockedFields.push({\n fieldId: field.storageId,\n multipleValues: !!field.multipleValues,\n type: baseType,\n ...lockedFieldData\n });\n }\n // no need to update anything if no locked fields were added\n if (lockedFields.length === 0) {\n return;\n }\n\n const newLockedFields = existingLockedFields.concat(lockedFields);\n\n try {\n await context.cms.updateModelDirect({\n original: model,\n model: {\n ...model,\n lockedFields: newLockedFields\n }\n });\n model.lockedFields = newLockedFields;\n } catch (ex) {\n throw new WebinyError(\n `Could not update model \"${model.modelId}\" with new locked fields.`,\n \"MODEL_LOCKED_FIELDS_UPDATE_FAILED\",\n ex\n );\n }\n};\n\nexport interface MarkFieldsUnlockedParams {\n context: CmsContext;\n model: CmsModel;\n}\nexport const markUnlockedFields = async (params: MarkFieldsUnlockedParams) => {\n const { context, model } = params;\n /**\n * If the model is registered via a plugin, we don't need do process anything.\n */\n const plugins = context.plugins.byType<CmsModelPlugin>(CmsModelPlugin.type);\n if (plugins.find(plugin => plugin.contentModel.modelId === model.modelId)) {\n return;\n }\n\n try {\n await context.cms.updateModelDirect({\n original: model,\n model: {\n ...model,\n lockedFields: []\n }\n });\n model.lockedFields = [];\n } catch (ex) {\n throw new WebinyError(\n `Could not update model \"${model.modelId}\" with unlocked fields.`,\n \"MODEL_UNLOCKED_FIELDS_UPDATE_FAILED\",\n ex\n );\n }\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAEA;;AACA;;AAOO,MAAMA,gBAAgB,GAAG,MAAOC,MAAP,IAAyD;EACrF,MAAM;IAAEC,KAAF;IAASC;EAAT,IAAqBF,MAA3B;EACA;AACJ;AACA;;EACI,MAAMG,OAAO,GAAGD,OAAO,CAACC,OAAR,CAAgBC,MAAhB,CAAuCC,8BAAA,CAAeC,IAAtD,CAAhB;;EACA,IAAIH,OAAO,CAACI,IAAR,CAAaC,MAAM,IAAIA,M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
+
id: string;
|
|
4
|
+
modelId: string;
|
|
5
|
+
}
|
|
6
|
+
interface Params {
|
|
7
|
+
context: CmsContext;
|
|
8
|
+
model: CmsModel;
|
|
9
|
+
input: Record<string, ReferenceObject | ReferenceObject[]>;
|
|
10
|
+
validateEntries?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare const referenceFieldsMapping: (params: Params) => Promise<Record<string, any>>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.referenceFieldsMapping = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
14
|
+
var _dotProp = _interopRequireDefault(require("dot-prop"));
|
|
15
|
+
|
|
16
|
+
var _utils = require("@webiny/utils");
|
|
17
|
+
|
|
18
|
+
var _getBaseFieldType = require("../../utils/getBaseFieldType");
|
|
19
|
+
|
|
20
|
+
const buildReferenceFieldPaths = params => {
|
|
21
|
+
const {
|
|
22
|
+
fields,
|
|
23
|
+
parentPaths: initialParentPaths,
|
|
24
|
+
input
|
|
25
|
+
} = params;
|
|
26
|
+
const parentPaths = [...initialParentPaths];
|
|
27
|
+
const isMultipleValues = Array.isArray(input);
|
|
28
|
+
return fields.filter(field => ["object", "ref"].includes((0, _getBaseFieldType.getBaseFieldType)(field))).reduce((collection, field) => {
|
|
29
|
+
var _field$settings2;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* First we check the ref field
|
|
33
|
+
*/
|
|
34
|
+
const baseType = (0, _getBaseFieldType.getBaseFieldType)(field);
|
|
35
|
+
|
|
36
|
+
if (baseType === "ref") {
|
|
37
|
+
const parentPathsValue = parentPaths.length > 0 ? `${parentPaths.join(".")}.` : "";
|
|
38
|
+
|
|
39
|
+
if (field.multipleValues) {
|
|
40
|
+
const inputValue = _dotProp.default.get(input, `${field.fieldId}`, []);
|
|
41
|
+
|
|
42
|
+
if (Array.isArray(inputValue) === false) {
|
|
43
|
+
return collection;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
for (const key in inputValue) {
|
|
47
|
+
const path = `${parentPathsValue}${field.fieldId}.${key}`;
|
|
48
|
+
collection.push(path);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return collection;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (isMultipleValues) {
|
|
55
|
+
for (const key in input) {
|
|
56
|
+
const path = `${parentPathsValue}${key}.${field.fieldId}`;
|
|
57
|
+
collection.push(path);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return collection;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
collection.push(`${parentPathsValue}${field.fieldId}`);
|
|
64
|
+
return collection;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Then we move onto the object field
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
const parentPathsValue = parentPaths.length > 0 ? `${parentPaths.join(".")}.` : "";
|
|
72
|
+
/**
|
|
73
|
+
* This is if received input is array. We need to map key with fieldId at this point.
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
if (isMultipleValues) {
|
|
77
|
+
for (const key in input) {
|
|
78
|
+
const path = `${parentPathsValue}${key}.${field.fieldId}`;
|
|
79
|
+
collection.push(path);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return collection;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const objFieldPath = `${field.fieldId}`;
|
|
86
|
+
|
|
87
|
+
const objFieldInputValue = _dotProp.default.get(input, objFieldPath, []);
|
|
88
|
+
/**
|
|
89
|
+
* If field is multiple values one, we need to go through the input and use the existing keys.
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
if (field.multipleValues) {
|
|
94
|
+
if (Array.isArray(objFieldInputValue) === false) {
|
|
95
|
+
return collection;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
for (const key in objFieldInputValue) {
|
|
99
|
+
var _field$settings;
|
|
100
|
+
|
|
101
|
+
const result = buildReferenceFieldPaths({
|
|
102
|
+
fields: ((_field$settings = field.settings) === null || _field$settings === void 0 ? void 0 : _field$settings.fields) || [],
|
|
103
|
+
input: objFieldInputValue[key],
|
|
104
|
+
parentPaths: parentPaths.concat([field.fieldId, key])
|
|
105
|
+
});
|
|
106
|
+
collection.push(...result);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return collection;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Single value reference field.
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
const results = buildReferenceFieldPaths({
|
|
117
|
+
fields: ((_field$settings2 = field.settings) === null || _field$settings2 === void 0 ? void 0 : _field$settings2.fields) || [],
|
|
118
|
+
input: objFieldInputValue,
|
|
119
|
+
parentPaths: parentPaths.concat([field.fieldId])
|
|
120
|
+
});
|
|
121
|
+
return collection.concat(results);
|
|
122
|
+
}, []);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const getReferenceFieldValue = ref => {
|
|
126
|
+
if (!ref) {
|
|
127
|
+
return {
|
|
128
|
+
id: null,
|
|
129
|
+
modelId: null
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
id: (ref.id || ref.entryId || "").trim() || null,
|
|
135
|
+
modelId: (ref.modelId || "").trim() || null
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const referenceFieldsMapping = async params => {
|
|
140
|
+
const {
|
|
141
|
+
context,
|
|
142
|
+
model,
|
|
143
|
+
input,
|
|
144
|
+
validateEntries = false
|
|
145
|
+
} = params;
|
|
146
|
+
let output = (0, _objectSpread2.default)({}, input);
|
|
147
|
+
const referenceFieldPaths = buildReferenceFieldPaths({
|
|
148
|
+
fields: model.fields,
|
|
149
|
+
input,
|
|
150
|
+
parentPaths: []
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
if (referenceFieldPaths.length === 0) {
|
|
154
|
+
return output;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const referencesByModel = {};
|
|
158
|
+
const pathsByReferenceId = {};
|
|
159
|
+
|
|
160
|
+
for (const path of referenceFieldPaths) {
|
|
161
|
+
const ref = _dotProp.default.get(output, path);
|
|
162
|
+
|
|
163
|
+
const {
|
|
164
|
+
id,
|
|
165
|
+
modelId
|
|
166
|
+
} = getReferenceFieldValue(ref);
|
|
167
|
+
|
|
168
|
+
if (!id || !modelId) {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (!referencesByModel[modelId]) {
|
|
173
|
+
referencesByModel[modelId] = [];
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
referencesByModel[modelId].push(id);
|
|
177
|
+
|
|
178
|
+
if (!pathsByReferenceId[id]) {
|
|
179
|
+
pathsByReferenceId[id] = [];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
pathsByReferenceId[id].push(path);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Again, no point in going further.
|
|
186
|
+
*/
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
if (Object.keys(referencesByModel).length === 0) {
|
|
190
|
+
return output;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Load all models and use only those that are used in reference.
|
|
194
|
+
*/
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
const models = (await context.cms.listModels()).filter(model => {
|
|
198
|
+
const entries = referencesByModel[model.modelId];
|
|
199
|
+
|
|
200
|
+
if (!Array.isArray(entries) || entries.length === 0) {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return true;
|
|
205
|
+
});
|
|
206
|
+
/**
|
|
207
|
+
* Check for any model existence, just in case.
|
|
208
|
+
*/
|
|
209
|
+
|
|
210
|
+
if (models.length === 0) {
|
|
211
|
+
return output;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Load all the entries by their ID
|
|
215
|
+
*/
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
const promises = models.map(model => {
|
|
219
|
+
return context.cms.getEntriesByIds(model, referencesByModel[model.modelId]);
|
|
220
|
+
});
|
|
221
|
+
const results = await Promise.all(promises);
|
|
222
|
+
const records = results.reduce((collection, entries) => {
|
|
223
|
+
for (const entry of entries) {
|
|
224
|
+
collection[entry.id] = {
|
|
225
|
+
id: entry.id,
|
|
226
|
+
entryId: entry.entryId,
|
|
227
|
+
modelId: entry.modelId
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return collection;
|
|
232
|
+
}, {});
|
|
233
|
+
/**
|
|
234
|
+
* Verify that all referenced entries actually exist.
|
|
235
|
+
*/
|
|
236
|
+
|
|
237
|
+
for (const modelId in referencesByModel) {
|
|
238
|
+
const entries = referencesByModel[modelId];
|
|
239
|
+
|
|
240
|
+
for (const id of entries) {
|
|
241
|
+
if (records[id]) {
|
|
242
|
+
continue;
|
|
243
|
+
} else if (validateEntries) {
|
|
244
|
+
throw new _error.default(`Missing referenced entry with id "${id}" in model "${modelId}".`, "ENTRY_NOT_FOUND", {
|
|
245
|
+
id,
|
|
246
|
+
model: modelId
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const {
|
|
251
|
+
id: entryId
|
|
252
|
+
} = (0, _utils.parseIdentifier)(id);
|
|
253
|
+
records[id] = {
|
|
254
|
+
id,
|
|
255
|
+
entryId,
|
|
256
|
+
modelId
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* In the end, assign the entryId, id and model values to the output.
|
|
262
|
+
*/
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
for (const id in pathsByReferenceId) {
|
|
266
|
+
const entry = records[id];
|
|
267
|
+
const paths = pathsByReferenceId[id];
|
|
268
|
+
|
|
269
|
+
if (!entry) {
|
|
270
|
+
if (validateEntries) {
|
|
271
|
+
throw new _error.default("Missing entry in records.", "ENTRY_ERROR", {
|
|
272
|
+
id,
|
|
273
|
+
paths
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
for (const path of paths) {
|
|
281
|
+
output = _dotProp.default.set(output, path, {
|
|
282
|
+
id: entry.id,
|
|
283
|
+
entryId: entry.entryId,
|
|
284
|
+
modelId: entry.modelId
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return output;
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
exports.referenceFieldsMapping = referenceFieldsMapping;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["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","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\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\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(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) === 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) || 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) {\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) {\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;;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,CAA2B,IAAAC,kCAAA,EAAiBF,KAAjB,CAA3B,CAD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AhC;;IACA,IAAI,CAACwB,KAAL,EAAY;MACR,IAAIjB,eAAJ,EAAqB;QACjB,MAAM,IAAIkB,cAAJ,CAAgB,2BAAhB,EAA6C,aAA7C,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"}
|
|
@@ -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,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSearchableFields = void 0;
|
|
7
|
+
|
|
8
|
+
const buildSearchableFieldList = params => {
|
|
9
|
+
const {
|
|
10
|
+
input,
|
|
11
|
+
plugins,
|
|
12
|
+
fields,
|
|
13
|
+
parents
|
|
14
|
+
} = params;
|
|
15
|
+
return fields.reduce((result, field) => {
|
|
16
|
+
var _field$settings;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* We need to check if the field is full text searchable, and for that we need a plugin for the field type.
|
|
20
|
+
*/
|
|
21
|
+
const plugin = plugins[field.type];
|
|
22
|
+
|
|
23
|
+
if (!plugin) {
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* There is a possibility that searchable fields exist in nested object field, so check that as well.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
const childFields = ((_field$settings = field.settings) === null || _field$settings === void 0 ? void 0 : _field$settings.fields) || [];
|
|
32
|
+
|
|
33
|
+
if (childFields.length > 0) {
|
|
34
|
+
/**
|
|
35
|
+
* So we build a list of searchable child fields and push it into the main result set.
|
|
36
|
+
*/
|
|
37
|
+
const childResults = buildSearchableFieldList({
|
|
38
|
+
fields: childFields,
|
|
39
|
+
parents: [...parents, field.fieldId],
|
|
40
|
+
plugins,
|
|
41
|
+
input
|
|
42
|
+
});
|
|
43
|
+
result.push(...childResults);
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* If not searchable, continue further.
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
if (!plugin.fullTextSearch) {
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Combine all parent paths with the current one and push it.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
const path = [...parents, field.fieldId].join(".");
|
|
60
|
+
result.push(path);
|
|
61
|
+
return result;
|
|
62
|
+
}, []);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const getSearchableFields = params => {
|
|
66
|
+
const {
|
|
67
|
+
plugins,
|
|
68
|
+
input,
|
|
69
|
+
fields
|
|
70
|
+
} = params;
|
|
71
|
+
const fieldPluginMap = plugins.byType("cms-model-field-to-graphql").reduce((collection, field) => {
|
|
72
|
+
collection[field.fieldType] = field;
|
|
73
|
+
return collection;
|
|
74
|
+
}, {});
|
|
75
|
+
return buildSearchableFieldList({
|
|
76
|
+
fields,
|
|
77
|
+
input,
|
|
78
|
+
plugins: fieldPluginMap,
|
|
79
|
+
parents: []
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
exports.getSearchableFields = getSearchableFields;
|
|
@@ -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","path","join","getSearchableFields","fieldPluginMap","byType","collection","fieldType"],"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) {\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, CmsModelFieldToGraphQLP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E,OAAF;IAAWD,KAAX;IAAkBE;EAAlB,IAA6BH,MAAnC;EACA,MAAMoB,cAAc,GAAGlB,OAAO,CACzBmB,MADkB,CACmB,4BADnB,EAElBhB,MAFkB,CAEX,CAACiB,UAAD,EAAaf,KAAb,KAAuB;IAC3Be,UAAU,CAACf,KAAK,CAACgB,SAAP,CAAV,GAA8BhB,KAA9B;IACA,OAAOe,UAAP;EACH,CALkB,EAKhB,EALgB,CAAvB;EAOA,OAAOvB,wBAAwB,CAAC;IAC5BI,MAD4B;IAE5BF,KAF4B;IAG5BC,OAAO,EAAEkB,cAHmB;IAI5BhB,OAAO,EAAE;EAJmB,CAAD,CAA/B;AAMH,CAfM"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CmsEntryContext, CmsContext, HeadlessCmsStorageOperations } from "../types";
|
|
2
|
+
import { SecurityIdentity } from "@webiny/api-security/types";
|
|
3
|
+
import { Tenant } from "@webiny/api-tenancy/types";
|
|
4
|
+
export declare const STATUS_DRAFT = "draft";
|
|
5
|
+
export declare const STATUS_PUBLISHED = "published";
|
|
6
|
+
export declare const STATUS_UNPUBLISHED = "unpublished";
|
|
7
|
+
export interface CreateContentEntryCrudParams {
|
|
8
|
+
storageOperations: HeadlessCmsStorageOperations;
|
|
9
|
+
context: CmsContext;
|
|
10
|
+
getIdentity: () => SecurityIdentity;
|
|
11
|
+
getTenant: () => Tenant;
|
|
12
|
+
}
|
|
13
|
+
export declare const createContentEntryCrud: (params: CreateContentEntryCrudParams) => CmsEntryContext;
|