@webiny/api-headless-cms 0.0.0-unstable.d4f203fa97 → 0.0.0-unstable.d7f521b032
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/context.d.ts +5 -2
- package/context.js +53 -19
- package/context.js.map +1 -1
- package/crud/contentEntry/afterDelete.js +0 -5
- package/crud/contentEntry/afterDelete.js.map +1 -1
- package/crud/contentEntry/beforeCreate.js +0 -3
- package/crud/contentEntry/beforeCreate.js.map +1 -1
- package/crud/contentEntry/beforeUpdate.js +0 -3
- package/crud/contentEntry/beforeUpdate.js.map +1 -1
- package/crud/contentEntry/entryDataValidation.js +1 -40
- package/crud/contentEntry/entryDataValidation.js.map +1 -1
- package/crud/contentEntry/markLockedFields.js +16 -29
- package/crud/contentEntry/markLockedFields.js.map +1 -1
- package/crud/contentEntry/referenceFieldsMapping.js +12 -64
- package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
- package/crud/contentEntry/searchableFields.d.ts +9 -0
- package/crud/contentEntry/searchableFields.js +72 -0
- package/crud/contentEntry/searchableFields.js.map +1 -0
- package/crud/contentEntry.crud.js +120 -181
- package/crud/contentEntry.crud.js.map +1 -1
- package/crud/contentModel/afterCreate.js +0 -2
- package/crud/contentModel/afterCreate.js.map +1 -1
- package/crud/contentModel/afterCreateFrom.js +0 -2
- package/crud/contentModel/afterCreateFrom.js.map +1 -1
- package/crud/contentModel/afterDelete.js +0 -2
- package/crud/contentModel/afterDelete.js.map +1 -1
- package/crud/contentModel/afterUpdate.js +0 -2
- package/crud/contentModel/afterUpdate.js.map +1 -1
- package/crud/contentModel/beforeCreate.d.ts +2 -3
- package/crud/contentModel/beforeCreate.js +7 -36
- package/crud/contentModel/beforeCreate.js.map +1 -1
- package/crud/contentModel/beforeDelete.js +0 -10
- package/crud/contentModel/beforeDelete.js.map +1 -1
- package/crud/contentModel/beforeUpdate.d.ts +2 -4
- package/crud/contentModel/beforeUpdate.js +2 -7
- package/crud/contentModel/beforeUpdate.js.map +1 -1
- package/crud/contentModel/contentModelManagerFactory.js +0 -7
- package/crud/contentModel/contentModelManagerFactory.js.map +1 -1
- package/crud/contentModel/createFieldStorageId.js +4 -3
- package/crud/contentModel/createFieldStorageId.js.map +1 -1
- package/crud/contentModel/models.js +12 -0
- package/crud/contentModel/models.js.map +1 -1
- package/crud/contentModel/systemFields.js.map +1 -1
- package/crud/contentModel/validateLayout.js +0 -8
- package/crud/contentModel/validateLayout.js.map +1 -1
- package/crud/contentModel/validateModel.d.ts +3 -4
- package/crud/contentModel/validateModel.js +6 -11
- package/crud/contentModel/validateModel.js.map +1 -1
- package/crud/contentModel/validateModelFields.d.ts +3 -4
- package/crud/contentModel/validateModelFields.js +118 -97
- package/crud/contentModel/validateModelFields.js.map +1 -1
- package/crud/contentModel/validation.d.ts +477 -0
- package/crud/contentModel/validation.js +97 -0
- package/crud/contentModel/validation.js.map +1 -0
- package/crud/contentModel.crud.js +219 -269
- package/crud/contentModel.crud.js.map +1 -1
- package/crud/contentModelGroup/beforeCreate.js +0 -12
- package/crud/contentModelGroup/beforeCreate.js.map +1 -1
- package/crud/contentModelGroup/beforeDelete.js +0 -8
- package/crud/contentModelGroup/beforeDelete.js.map +1 -1
- package/crud/contentModelGroup/beforeUpdate.js +0 -5
- package/crud/contentModelGroup/beforeUpdate.js.map +1 -1
- package/crud/contentModelGroup/validation.d.ts +30 -0
- package/crud/contentModelGroup/validation.js +34 -0
- package/crud/contentModelGroup/validation.js.map +1 -0
- package/crud/contentModelGroup.crud.js +53 -95
- package/crud/contentModelGroup.crud.js.map +1 -1
- package/crud/settings.crud.js +0 -12
- package/crud/settings.crud.js.map +1 -1
- package/crud/system.crud.js +2 -37
- package/crud/system.crud.js.map +1 -1
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +0 -13
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.d.ts +11 -0
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +203 -0
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -0
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +0 -53
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/index.d.ts +2 -1
- package/fieldConverters/index.js +2 -5
- package/fieldConverters/index.js.map +1 -1
- package/graphql/buildSchemaPlugins.d.ts +8 -3
- package/graphql/buildSchemaPlugins.js +6 -14
- package/graphql/buildSchemaPlugins.js.map +1 -1
- package/graphql/createExecutableSchema.d.ts +7 -0
- package/graphql/createExecutableSchema.js +29 -0
- package/graphql/createExecutableSchema.js.map +1 -0
- package/graphql/generateSchema.d.ts +8 -0
- package/graphql/generateSchema.js +31 -0
- package/graphql/generateSchema.js.map +1 -0
- package/graphql/graphQLHandlerFactory.js +90 -74
- package/graphql/graphQLHandlerFactory.js.map +1 -1
- package/graphql/index.d.ts +1 -3
- package/graphql/index.js +2 -46
- package/graphql/index.js.map +1 -1
- package/graphql/schema/baseContentSchema.d.ts +6 -2
- package/graphql/schema/baseContentSchema.js +9 -13
- package/graphql/schema/baseContentSchema.js.map +1 -1
- package/graphql/schema/baseSchema.d.ts +3 -0
- package/graphql/schema/baseSchema.js +53 -0
- package/graphql/schema/baseSchema.js.map +1 -0
- package/graphql/schema/contentEntries.d.ts +6 -2
- package/graphql/schema/contentEntries.js +39 -65
- package/graphql/schema/contentEntries.js.map +1 -1
- package/graphql/schema/contentModelGroups.d.ts +6 -2
- package/graphql/schema/contentModelGroups.js +9 -22
- package/graphql/schema/contentModelGroups.js.map +1 -1
- package/graphql/schema/contentModels.d.ts +6 -2
- package/graphql/schema/contentModels.js +42 -25
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createFieldResolvers.d.ts +1 -1
- package/graphql/schema/createFieldResolvers.js +20 -27
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/graphql/schema/createManageResolvers.js +0 -26
- package/graphql/schema/createManageResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.d.ts +2 -0
- package/graphql/schema/createManageSDL.js +8 -19
- package/graphql/schema/createManageSDL.js.map +1 -1
- package/graphql/schema/createPreviewResolvers.js +0 -10
- package/graphql/schema/createPreviewResolvers.js.map +1 -1
- package/graphql/schema/createReadResolvers.js +5 -10
- package/graphql/schema/createReadResolvers.js.map +1 -1
- package/graphql/schema/createReadSDL.d.ts +2 -0
- package/graphql/schema/createReadSDL.js +11 -15
- package/graphql/schema/createReadSDL.js.map +1 -1
- package/graphql/schema/resolvers/commonFieldResolvers.js +0 -2
- package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveCreate.js +0 -3
- package/graphql/schema/resolvers/manage/resolveCreate.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveCreateFrom.js +0 -3
- package/graphql/schema/resolvers/manage/resolveCreateFrom.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveDelete.js +0 -6
- package/graphql/schema/resolvers/manage/resolveDelete.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGet.js +0 -16
- package/graphql/schema/resolvers/manage/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGetByIds.js +0 -3
- package/graphql/schema/resolvers/manage/resolveGetByIds.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGetRevisions.js +0 -3
- package/graphql/schema/resolvers/manage/resolveGetRevisions.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveList.js +0 -3
- package/graphql/schema/resolvers/manage/resolveList.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolvePublish.js +0 -3
- package/graphql/schema/resolvers/manage/resolvePublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveRepublish.js +0 -3
- package/graphql/schema/resolvers/manage/resolveRepublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveUnpublish.js +0 -3
- package/graphql/schema/resolvers/manage/resolveUnpublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveUpdate.js +0 -3
- package/graphql/schema/resolvers/manage/resolveUpdate.js.map +1 -1
- package/graphql/schema/resolvers/preview/resolveGet.js +0 -8
- package/graphql/schema/resolvers/preview/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/preview/resolveList.js +0 -3
- package/graphql/schema/resolvers/preview/resolveList.js.map +1 -1
- package/graphql/schema/resolvers/read/resolveGet.js +0 -8
- package/graphql/schema/resolvers/read/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/read/resolveList.js +0 -3
- package/graphql/schema/resolvers/read/resolveList.js.map +1 -1
- package/graphql/schema/schemaPlugins.d.ts +8 -3
- package/graphql/schema/schemaPlugins.js +63 -65
- package/graphql/schema/schemaPlugins.js.map +1 -1
- package/graphql/system.js +69 -85
- package/graphql/system.js.map +1 -1
- package/graphqlFields/boolean.js +0 -12
- package/graphqlFields/boolean.js.map +1 -1
- package/graphqlFields/datetime.js +0 -17
- package/graphqlFields/datetime.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +2 -0
- package/graphqlFields/dynamicZone/dynamicZoneField.js +208 -0
- package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.d.ts +3 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js +63 -0
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js.map +1 -0
- package/graphqlFields/dynamicZone/index.d.ts +2 -0
- package/graphqlFields/dynamicZone/index.js +19 -0
- package/graphqlFields/dynamicZone/index.js.map +1 -0
- package/graphqlFields/file.js +0 -8
- package/graphqlFields/file.js.map +1 -1
- package/graphqlFields/helpers.js +0 -10
- package/graphqlFields/helpers.js.map +1 -1
- package/graphqlFields/index.d.ts +1 -1
- package/graphqlFields/index.js +2 -12
- package/graphqlFields/index.js.map +1 -1
- package/graphqlFields/longText.js +0 -10
- package/graphqlFields/longText.js.map +1 -1
- package/graphqlFields/number.js +0 -12
- package/graphqlFields/number.js.map +1 -1
- package/graphqlFields/object.js +112 -98
- package/graphqlFields/object.js.map +1 -1
- package/graphqlFields/ref.js +48 -96
- package/graphqlFields/ref.js.map +1 -1
- package/graphqlFields/richText.js +0 -9
- package/graphqlFields/richText.js.map +1 -1
- package/graphqlFields/text.js +0 -11
- package/graphqlFields/text.js.map +1 -1
- package/index.d.ts +3 -3
- package/index.js +3 -26
- package/index.js.map +1 -1
- package/modelManager/DefaultCmsModelManager.js +0 -16
- package/modelManager/DefaultCmsModelManager.js.map +1 -1
- package/modelManager/index.js +0 -4
- package/modelManager/index.js.map +1 -1
- package/package.json +28 -28
- package/parameters/context.js +0 -4
- package/parameters/context.js.map +1 -1
- package/parameters/header.js +0 -11
- package/parameters/header.js.map +1 -1
- package/parameters/index.js +0 -8
- package/parameters/index.js.map +1 -1
- package/parameters/manual.js +1 -8
- package/parameters/manual.js.map +1 -1
- package/parameters/path.js +0 -11
- package/parameters/path.js.map +1 -1
- package/plugins/CmsGraphQLSchemaPlugin.d.ts +5 -0
- package/plugins/CmsGraphQLSchemaPlugin.js +12 -0
- package/plugins/CmsGraphQLSchemaPlugin.js.map +1 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.d.ts +20 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.js +28 -0
- package/plugins/CmsGraphQLSchemaSorterPlugin.js.map +1 -0
- package/plugins/CmsGroupPlugin.js +0 -8
- package/plugins/CmsGroupPlugin.js.map +1 -1
- package/plugins/CmsModelFieldConverterPlugin.d.ts +2 -2
- package/plugins/CmsModelFieldConverterPlugin.js +0 -5
- package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
- package/plugins/CmsModelPlugin.js +2 -38
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/plugins/CmsParametersPlugin.js +0 -7
- package/plugins/CmsParametersPlugin.js.map +1 -1
- package/plugins/StorageTransformPlugin.d.ts +11 -11
- package/plugins/StorageTransformPlugin.js +0 -9
- package/plugins/StorageTransformPlugin.js.map +1 -1
- package/plugins/index.d.ts +2 -0
- package/plugins/index.js +22 -10
- package/plugins/index.js.map +1 -1
- package/storage/default.js +0 -3
- package/storage/default.js.map +1 -1
- package/storage/object.js +4 -20
- package/storage/object.js.map +1 -1
- package/types.d.ts +235 -57
- package/types.js +62 -69
- package/types.js.map +1 -1
- package/upgrades/5.33.0/index.js +3 -26
- package/upgrades/5.33.0/index.js.map +1 -1
- package/upgrades/index.js +0 -3
- package/upgrades/index.js.map +1 -1
- package/utils/access.js +11 -25
- package/utils/access.js.map +1 -1
- package/utils/converters/Converter.js +0 -13
- package/utils/converters/Converter.js.map +1 -1
- package/utils/converters/ConverterCollection.js +14 -34
- package/utils/converters/ConverterCollection.js.map +1 -1
- package/utils/converters/valueKeyStorageConverter.js +0 -26
- package/utils/converters/valueKeyStorageConverter.js.map +1 -1
- package/utils/createTypeFromFields.d.ts +15 -0
- package/utils/createTypeFromFields.js +64 -0
- package/utils/createTypeFromFields.js.map +1 -0
- package/utils/createTypeName.js +2 -9
- package/utils/createTypeName.js.map +1 -1
- package/utils/entryStorage.js +22 -35
- package/utils/entryStorage.js.map +1 -1
- package/utils/filterAsync.js +0 -5
- package/utils/filterAsync.js.map +1 -1
- package/utils/getBaseFieldType.d.ts +4 -0
- package/utils/getBaseFieldType.js +10 -0
- package/utils/getBaseFieldType.js.map +1 -0
- package/utils/getEntryTitle.js +0 -9
- package/utils/getEntryTitle.js.map +1 -1
- package/utils/getSchemaFromFieldPlugins.d.ts +4 -7
- package/utils/getSchemaFromFieldPlugins.js +23 -19
- package/utils/getSchemaFromFieldPlugins.js.map +1 -1
- package/utils/ownership.js +0 -8
- package/utils/ownership.js.map +1 -1
- package/utils/permissions.js +8 -23
- package/utils/permissions.js.map +1 -1
- package/utils/pluralizedTypeName.js +0 -6
- package/utils/pluralizedTypeName.js.map +1 -1
- package/utils/renderFields.js +2 -9
- package/utils/renderFields.js.map +1 -1
- package/utils/renderGetFilterFields.js +6 -14
- package/utils/renderGetFilterFields.js.map +1 -1
- package/utils/renderInputFields.js +2 -9
- package/utils/renderInputFields.js.map +1 -1
- package/utils/renderListFilterFields.js +4 -10
- package/utils/renderListFilterFields.js.map +1 -1
- package/utils/renderSortEnum.d.ts +7 -4
- package/utils/renderSortEnum.js +21 -11
- package/utils/renderSortEnum.js.map +1 -1
- package/utils/toSlug.js +0 -4
- package/utils/toSlug.js.map +1 -1
- package/validators/dateGte.js +0 -7
- package/validators/dateGte.js.map +1 -1
- package/validators/dateLte.js +0 -7
- package/validators/dateLte.js.map +1 -1
- package/validators/dynamicZone.d.ts +2 -0
- package/validators/dynamicZone.js +20 -0
- package/validators/dynamicZone.js.map +1 -0
- package/validators/gte.js +0 -8
- package/validators/gte.js.map +1 -1
- package/validators/in.js +0 -8
- package/validators/in.js.map +1 -1
- package/validators/index.js +2 -16
- package/validators/index.js.map +1 -1
- package/validators/lte.js +0 -8
- package/validators/lte.js.map +1 -1
- package/validators/maxLength.js +0 -8
- package/validators/maxLength.js.map +1 -1
- package/validators/minLength.js +0 -8
- package/validators/minLength.js.map +1 -1
- package/validators/pattern.js +0 -9
- package/validators/pattern.js.map +1 -1
- package/validators/patternPlugins/email.js +0 -2
- package/validators/patternPlugins/email.js.map +1 -1
- package/validators/patternPlugins/index.js +0 -8
- package/validators/patternPlugins/index.js.map +1 -1
- package/validators/patternPlugins/lowerCase.js +0 -2
- package/validators/patternPlugins/lowerCase.js.map +1 -1
- package/validators/patternPlugins/lowerCaseSpace.js +0 -2
- package/validators/patternPlugins/lowerCaseSpace.js.map +1 -1
- package/validators/patternPlugins/upperCase.js +0 -2
- package/validators/patternPlugins/upperCase.js.map +1 -1
- package/validators/patternPlugins/upperCaseSpace.js +0 -2
- package/validators/patternPlugins/upperCaseSpace.js.map +1 -1
- package/validators/patternPlugins/url.js +0 -2
- package/validators/patternPlugins/url.js.map +1 -1
- package/validators/required.js +0 -5
- package/validators/required.js.map +1 -1
- package/validators/timeGte.js +0 -8
- package/validators/timeGte.js.map +1 -1
- package/validators/timeLte.js +0 -8
- package/validators/timeLte.js.map +1 -1
- package/validators/unique.js +0 -7
- package/validators/unique.js.map +1 -1
- package/crud/index.d.ts +0 -6
- package/crud/index.js +0 -85
- package/crud/index.js.map +0 -1
- package/graphql/schema/resolvers/manage/resolveRequestChanges.d.ts +0 -7
- package/graphql/schema/resolvers/manage/resolveRequestChanges.js +0 -21
- package/graphql/schema/resolvers/manage/resolveRequestChanges.js.map +0 -1
- package/graphql/schema/resolvers/manage/resolveRequestReview.d.ts +0 -7
- package/graphql/schema/resolvers/manage/resolveRequestReview.js +0 -21
- package/graphql/schema/resolvers/manage/resolveRequestReview.js.map +0 -1
- package/utils/filterModelFields.d.ts +0 -16
- package/utils/filterModelFields.js +0 -77
- package/utils/filterModelFields.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["markLockedFields","params","model","context","plugins","byType","CmsModelPlugin","type","find","plugin","contentModel","modelId","cmsLockedFieldPlugins","existingLockedFields","lockedFields","field","fields","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\";\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 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 ===
|
|
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","message","code","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 {\n message: ex.message,\n code: ex.code,\n data: ex.data\n }\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 {\n message: ex.message,\n code: ex.code,\n data: ex.data\n }\n );\n }\n};\n"],"mappings":";;;;;;;;AAAA;AAEA;AACA;AAOO,MAAMA,gBAAgB,GAAG,MAAOC,MAA8B,IAAoB;EACrF,MAAM;IAAEC,KAAK;IAAEC;EAAQ,CAAC,GAAGF,MAAM;EACjC;A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ChB,2BAA0BtC,KAAK,CAACS,OAAQ,yBAAwB,EACjE,qCAAqC,EACrC;MACI8B,OAAO,EAAEF,EAAE,CAACE,OAAO;MACnBC,IAAI,EAAEH,EAAE,CAACG,IAAI;MACbZ,IAAI,EAAES,EAAE,CAACT;IACb,CAAC,CACJ;EACL;AACJ,CAAC;AAAC"}
|
|
@@ -1,20 +1,15 @@
|
|
|
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
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
-
|
|
14
10
|
var _dotProp = _interopRequireDefault(require("dot-prop"));
|
|
15
|
-
|
|
16
11
|
var _utils = require("@webiny/utils");
|
|
17
|
-
|
|
12
|
+
var _getBaseFieldType = require("../../utils/getBaseFieldType");
|
|
18
13
|
const buildReferenceFieldPaths = params => {
|
|
19
14
|
const {
|
|
20
15
|
fields,
|
|
@@ -23,77 +18,61 @@ const buildReferenceFieldPaths = params => {
|
|
|
23
18
|
} = params;
|
|
24
19
|
const parentPaths = [...initialParentPaths];
|
|
25
20
|
const isMultipleValues = Array.isArray(input);
|
|
26
|
-
return fields.filter(field => ["object", "ref"].includes(
|
|
21
|
+
return fields.filter(field => ["object", "ref"].includes((0, _getBaseFieldType.getBaseFieldType)(field))).reduce((collection, field) => {
|
|
27
22
|
var _field$settings2;
|
|
28
|
-
|
|
29
23
|
/**
|
|
30
24
|
* First we check the ref field
|
|
31
25
|
*/
|
|
32
|
-
|
|
26
|
+
const baseType = (0, _getBaseFieldType.getBaseFieldType)(field);
|
|
27
|
+
if (baseType === "ref") {
|
|
33
28
|
const parentPathsValue = parentPaths.length > 0 ? `${parentPaths.join(".")}.` : "";
|
|
34
|
-
|
|
35
29
|
if (field.multipleValues) {
|
|
36
30
|
const inputValue = _dotProp.default.get(input, `${field.fieldId}`, []);
|
|
37
|
-
|
|
38
31
|
if (Array.isArray(inputValue) === false) {
|
|
39
32
|
return collection;
|
|
40
33
|
}
|
|
41
|
-
|
|
42
34
|
for (const key in inputValue) {
|
|
43
35
|
const path = `${parentPathsValue}${field.fieldId}.${key}`;
|
|
44
36
|
collection.push(path);
|
|
45
37
|
}
|
|
46
|
-
|
|
47
38
|
return collection;
|
|
48
39
|
}
|
|
49
|
-
|
|
50
40
|
if (isMultipleValues) {
|
|
51
41
|
for (const key in input) {
|
|
52
42
|
const path = `${parentPathsValue}${key}.${field.fieldId}`;
|
|
53
43
|
collection.push(path);
|
|
54
44
|
}
|
|
55
|
-
|
|
56
45
|
return collection;
|
|
57
46
|
}
|
|
58
|
-
|
|
59
47
|
collection.push(`${parentPathsValue}${field.fieldId}`);
|
|
60
48
|
return collection;
|
|
61
49
|
}
|
|
62
50
|
/**
|
|
63
51
|
* Then we move onto the object field
|
|
64
52
|
*/
|
|
65
|
-
|
|
66
|
-
|
|
67
53
|
const parentPathsValue = parentPaths.length > 0 ? `${parentPaths.join(".")}.` : "";
|
|
68
54
|
/**
|
|
69
55
|
* This is if received input is array. We need to map key with fieldId at this point.
|
|
70
56
|
*/
|
|
71
|
-
|
|
72
57
|
if (isMultipleValues) {
|
|
73
58
|
for (const key in input) {
|
|
74
59
|
const path = `${parentPathsValue}${key}.${field.fieldId}`;
|
|
75
60
|
collection.push(path);
|
|
76
61
|
}
|
|
77
|
-
|
|
78
62
|
return collection;
|
|
79
63
|
}
|
|
80
|
-
|
|
81
64
|
const objFieldPath = `${field.fieldId}`;
|
|
82
|
-
|
|
83
65
|
const objFieldInputValue = _dotProp.default.get(input, objFieldPath, []);
|
|
66
|
+
|
|
84
67
|
/**
|
|
85
68
|
* If field is multiple values one, we need to go through the input and use the existing keys.
|
|
86
69
|
*/
|
|
87
|
-
|
|
88
|
-
|
|
89
70
|
if (field.multipleValues) {
|
|
90
71
|
if (Array.isArray(objFieldInputValue) === false) {
|
|
91
72
|
return collection;
|
|
92
73
|
}
|
|
93
|
-
|
|
94
74
|
for (const key in objFieldInputValue) {
|
|
95
75
|
var _field$settings;
|
|
96
|
-
|
|
97
76
|
const result = buildReferenceFieldPaths({
|
|
98
77
|
fields: ((_field$settings = field.settings) === null || _field$settings === void 0 ? void 0 : _field$settings.fields) || [],
|
|
99
78
|
input: objFieldInputValue[key],
|
|
@@ -101,14 +80,12 @@ const buildReferenceFieldPaths = params => {
|
|
|
101
80
|
});
|
|
102
81
|
collection.push(...result);
|
|
103
82
|
}
|
|
104
|
-
|
|
105
83
|
return collection;
|
|
106
84
|
}
|
|
85
|
+
|
|
107
86
|
/**
|
|
108
87
|
* Single value reference field.
|
|
109
88
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
112
89
|
const results = buildReferenceFieldPaths({
|
|
113
90
|
fields: ((_field$settings2 = field.settings) === null || _field$settings2 === void 0 ? void 0 : _field$settings2.fields) || [],
|
|
114
91
|
input: objFieldInputValue,
|
|
@@ -117,7 +94,6 @@ const buildReferenceFieldPaths = params => {
|
|
|
117
94
|
return collection.concat(results);
|
|
118
95
|
}, []);
|
|
119
96
|
};
|
|
120
|
-
|
|
121
97
|
const getReferenceFieldValue = ref => {
|
|
122
98
|
if (!ref) {
|
|
123
99
|
return {
|
|
@@ -125,13 +101,11 @@ const getReferenceFieldValue = ref => {
|
|
|
125
101
|
modelId: null
|
|
126
102
|
};
|
|
127
103
|
}
|
|
128
|
-
|
|
129
104
|
return {
|
|
130
105
|
id: (ref.id || ref.entryId || "").trim() || null,
|
|
131
106
|
modelId: (ref.modelId || "").trim() || null
|
|
132
107
|
};
|
|
133
108
|
};
|
|
134
|
-
|
|
135
109
|
const referenceFieldsMapping = async params => {
|
|
136
110
|
const {
|
|
137
111
|
context,
|
|
@@ -145,72 +119,56 @@ const referenceFieldsMapping = async params => {
|
|
|
145
119
|
input,
|
|
146
120
|
parentPaths: []
|
|
147
121
|
});
|
|
148
|
-
|
|
149
122
|
if (referenceFieldPaths.length === 0) {
|
|
150
123
|
return output;
|
|
151
124
|
}
|
|
152
|
-
|
|
153
125
|
const referencesByModel = {};
|
|
154
126
|
const pathsByReferenceId = {};
|
|
155
|
-
|
|
156
127
|
for (const path of referenceFieldPaths) {
|
|
157
128
|
const ref = _dotProp.default.get(output, path);
|
|
158
|
-
|
|
159
129
|
const {
|
|
160
130
|
id,
|
|
161
131
|
modelId
|
|
162
132
|
} = getReferenceFieldValue(ref);
|
|
163
|
-
|
|
164
133
|
if (!id || !modelId) {
|
|
165
134
|
continue;
|
|
166
135
|
}
|
|
167
|
-
|
|
168
136
|
if (!referencesByModel[modelId]) {
|
|
169
137
|
referencesByModel[modelId] = [];
|
|
170
138
|
}
|
|
171
|
-
|
|
172
139
|
referencesByModel[modelId].push(id);
|
|
173
|
-
|
|
174
140
|
if (!pathsByReferenceId[id]) {
|
|
175
141
|
pathsByReferenceId[id] = [];
|
|
176
142
|
}
|
|
177
|
-
|
|
178
143
|
pathsByReferenceId[id].push(path);
|
|
179
144
|
}
|
|
145
|
+
|
|
180
146
|
/**
|
|
181
147
|
* Again, no point in going further.
|
|
182
148
|
*/
|
|
183
|
-
|
|
184
|
-
|
|
185
149
|
if (Object.keys(referencesByModel).length === 0) {
|
|
186
150
|
return output;
|
|
187
151
|
}
|
|
188
152
|
/**
|
|
189
153
|
* Load all models and use only those that are used in reference.
|
|
190
154
|
*/
|
|
191
|
-
|
|
192
|
-
|
|
193
155
|
const models = (await context.cms.listModels()).filter(model => {
|
|
194
156
|
const entries = referencesByModel[model.modelId];
|
|
195
|
-
|
|
196
|
-
if (Array.isArray(entries) === false || entries.length === 0) {
|
|
157
|
+
if (!Array.isArray(entries) || entries.length === 0) {
|
|
197
158
|
return false;
|
|
198
159
|
}
|
|
199
|
-
|
|
200
160
|
return true;
|
|
201
161
|
});
|
|
202
162
|
/**
|
|
203
163
|
* Check for any model existence, just in case.
|
|
204
164
|
*/
|
|
205
|
-
|
|
206
165
|
if (models.length === 0) {
|
|
207
166
|
return output;
|
|
208
167
|
}
|
|
168
|
+
|
|
209
169
|
/**
|
|
210
170
|
* Load all the entries by their ID
|
|
211
171
|
*/
|
|
212
|
-
|
|
213
|
-
|
|
214
172
|
const promises = models.map(model => {
|
|
215
173
|
return context.cms.getEntriesByIds(model, referencesByModel[model.modelId]);
|
|
216
174
|
});
|
|
@@ -223,26 +181,22 @@ const referenceFieldsMapping = async params => {
|
|
|
223
181
|
modelId: entry.modelId
|
|
224
182
|
};
|
|
225
183
|
}
|
|
226
|
-
|
|
227
184
|
return collection;
|
|
228
185
|
}, {});
|
|
229
186
|
/**
|
|
230
187
|
* Verify that all referenced entries actually exist.
|
|
231
188
|
*/
|
|
232
|
-
|
|
233
189
|
for (const modelId in referencesByModel) {
|
|
234
190
|
const entries = referencesByModel[modelId];
|
|
235
|
-
|
|
236
191
|
for (const id of entries) {
|
|
237
192
|
if (records[id]) {
|
|
238
193
|
continue;
|
|
239
|
-
} else if (validateEntries
|
|
194
|
+
} else if (validateEntries) {
|
|
240
195
|
throw new _error.default(`Missing referenced entry with id "${id}" in model "${modelId}".`, "ENTRY_NOT_FOUND", {
|
|
241
196
|
id,
|
|
242
197
|
model: modelId
|
|
243
198
|
});
|
|
244
199
|
}
|
|
245
|
-
|
|
246
200
|
const {
|
|
247
201
|
id: entryId
|
|
248
202
|
} = (0, _utils.parseIdentifier)(id);
|
|
@@ -253,26 +207,22 @@ const referenceFieldsMapping = async params => {
|
|
|
253
207
|
};
|
|
254
208
|
}
|
|
255
209
|
}
|
|
210
|
+
|
|
256
211
|
/**
|
|
257
212
|
* In the end, assign the entryId, id and model values to the output.
|
|
258
213
|
*/
|
|
259
|
-
|
|
260
|
-
|
|
261
214
|
for (const id in pathsByReferenceId) {
|
|
262
215
|
const entry = records[id];
|
|
263
216
|
const paths = pathsByReferenceId[id];
|
|
264
|
-
|
|
265
217
|
if (!entry) {
|
|
266
|
-
if (validateEntries
|
|
218
|
+
if (validateEntries) {
|
|
267
219
|
throw new _error.default("Missing entry in records.", "ENTRY_ERROR", {
|
|
268
220
|
id,
|
|
269
221
|
paths
|
|
270
222
|
});
|
|
271
223
|
}
|
|
272
|
-
|
|
273
224
|
continue;
|
|
274
225
|
}
|
|
275
|
-
|
|
276
226
|
for (const path of paths) {
|
|
277
227
|
output = _dotProp.default.set(output, path, {
|
|
278
228
|
id: entry.id,
|
|
@@ -281,8 +231,6 @@ const referenceFieldsMapping = async params => {
|
|
|
281
231
|
});
|
|
282
232
|
}
|
|
283
233
|
}
|
|
284
|
-
|
|
285
234
|
return output;
|
|
286
235
|
};
|
|
287
|
-
|
|
288
236
|
exports.referenceFieldsMapping = referenceFieldsMapping;
|
|
@@ -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,CAACE,IAAN,KAAe,KAAnB,EAA0B;MACtB,MAAMG,gBAAgB,GAAGZ,WAAW,CAACa,MAAZ,GAAqB,CAArB,GAA0B,GAAEb,WAAW,CAACc,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0B;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":["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,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,CAAC,CAACC,QAAQ,CAAC,IAAAC,kCAAgB,EAACF,KAAK,CAAC,CAAC,CAAC,CACpEG,MAAM,CAAC,CAACC,UAAU,EAAEJ,KAAK,KAAK;IAAA;IAC3B;AACZ;AACA;IACY,MAAMK,QAAQ,GAAG,IAAAH,kCAAgB,EAACF,KAAK,CAAC;IACxC,IAAIK,QAAQ,KAAK,KAAK,EAAE;MACpB,MAAMC,gBAAgB,GAAGb,WAAW,CAACc,MAAM,GAAG,CAAC,GAAI,GAAEd,WAAW,CAACe,IAAI,CAAC,GAAG,CAAE,GAAE,GAAG,EAAE;MAClF,IAAIR,KAAK,CAACS,cAAc,EAAE;QACtB,MAAMC,UAAU,GAAGC,gBAAO,CAACC,GAAG,CAACjB,KAAK,EA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|
|
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,72 @@
|
|
|
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
|
+
var _field$settings;
|
|
16
|
+
/**
|
|
17
|
+
* We need to check if the field is full text searchable, and for that we need a plugin for the field type.
|
|
18
|
+
*/
|
|
19
|
+
const plugin = plugins[field.type];
|
|
20
|
+
if (!plugin) {
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* There is a possibility that searchable fields exist in nested object field, so check that as well.
|
|
25
|
+
*/
|
|
26
|
+
const childFields = ((_field$settings = field.settings) === null || _field$settings === void 0 ? void 0 : _field$settings.fields) || [];
|
|
27
|
+
if (childFields.length > 0) {
|
|
28
|
+
/**
|
|
29
|
+
* So we build a list of searchable child fields and push it into the main result set.
|
|
30
|
+
*/
|
|
31
|
+
const childResults = buildSearchableFieldList({
|
|
32
|
+
fields: childFields,
|
|
33
|
+
parents: [...parents, field.fieldId],
|
|
34
|
+
plugins,
|
|
35
|
+
input
|
|
36
|
+
});
|
|
37
|
+
result.push(...childResults);
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* If not searchable, continue further.
|
|
42
|
+
*/
|
|
43
|
+
if (!plugin.fullTextSearch) {
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Combine all parent paths with the current one and push it.
|
|
49
|
+
*/
|
|
50
|
+
const path = [...parents, field.fieldId].join(".");
|
|
51
|
+
result.push(path);
|
|
52
|
+
return result;
|
|
53
|
+
}, []);
|
|
54
|
+
};
|
|
55
|
+
const getSearchableFields = params => {
|
|
56
|
+
const {
|
|
57
|
+
plugins,
|
|
58
|
+
input,
|
|
59
|
+
fields
|
|
60
|
+
} = params;
|
|
61
|
+
const fieldPluginMap = plugins.byType("cms-model-field-to-graphql").reduce((collection, field) => {
|
|
62
|
+
collection[field.fieldType] = field;
|
|
63
|
+
return collection;
|
|
64
|
+
}, {});
|
|
65
|
+
return buildSearchableFieldList({
|
|
66
|
+
fields,
|
|
67
|
+
input,
|
|
68
|
+
plugins: fieldPluginMap,
|
|
69
|
+
parents: []
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
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, 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;IAAA;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,GAAG,oBAAAH,KAAK,CAACI,QAAQ,oDAAd,gBAAgBR,MAAM,KAAI,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,K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