@webiny/api-headless-cms 0.0.0-unstable.5e7233243f → 0.0.0-unstable.60a863e033
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 +55 -25
- package/context.js.map +1 -1
- package/crud/contentEntry/afterDelete.d.ts +2 -2
- package/crud/contentEntry/afterDelete.js +2 -7
- package/crud/contentEntry/afterDelete.js.map +1 -1
- package/crud/contentEntry/beforeCreate.d.ts +2 -2
- package/crud/contentEntry/beforeCreate.js +2 -5
- package/crud/contentEntry/beforeCreate.js.map +1 -1
- package/crud/contentEntry/beforeUpdate.d.ts +2 -2
- package/crud/contentEntry/beforeUpdate.js +2 -5
- package/crud/contentEntry/beforeUpdate.js.map +1 -1
- package/crud/contentEntry/entryDataValidation.js +4 -47
- package/crud/contentEntry/entryDataValidation.js.map +1 -1
- package/crud/contentEntry/markLockedFields.js +22 -39
- package/crud/contentEntry/markLockedFields.js.map +1 -1
- package/crud/contentEntry/referenceFieldsMapping.js +15 -73
- 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.d.ts +0 -2
- package/crud/contentEntry.crud.js +292 -395
- package/crud/contentEntry.crud.js.map +1 -1
- package/crud/contentModel/afterCreate.d.ts +3 -3
- package/crud/contentModel/afterCreate.js +5 -7
- package/crud/contentModel/afterCreate.js.map +1 -1
- package/crud/contentModel/afterCreateFrom.d.ts +3 -3
- package/crud/contentModel/afterCreateFrom.js +5 -7
- package/crud/contentModel/afterCreateFrom.js.map +1 -1
- package/crud/contentModel/afterDelete.d.ts +3 -3
- package/crud/contentModel/afterDelete.js +5 -7
- package/crud/contentModel/afterDelete.js.map +1 -1
- package/crud/contentModel/afterUpdate.d.ts +3 -3
- package/crud/contentModel/afterUpdate.js +5 -7
- package/crud/contentModel/afterUpdate.js.map +1 -1
- package/crud/contentModel/beforeCreate.d.ts +5 -6
- package/crud/contentModel/beforeCreate.js +17 -46
- package/crud/contentModel/beforeCreate.js.map +1 -1
- package/crud/contentModel/beforeDelete.d.ts +3 -3
- package/crud/contentModel/beforeDelete.js +6 -16
- package/crud/contentModel/beforeDelete.js.map +1 -1
- package/crud/contentModel/beforeUpdate.d.ts +4 -6
- package/crud/contentModel/beforeUpdate.js +7 -12
- 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 +7 -12
- package/crud/contentModel/validateModel.js.map +1 -1
- package/crud/contentModel/validateModelFields.d.ts +3 -4
- package/crud/contentModel/validateModelFields.js +121 -104
- 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 +278 -304
- package/crud/contentModel.crud.js.map +1 -1
- package/crud/contentModelGroup/beforeCreate.d.ts +2 -2
- package/crud/contentModelGroup/beforeCreate.js +3 -15
- package/crud/contentModelGroup/beforeCreate.js.map +1 -1
- package/crud/contentModelGroup/beforeDelete.d.ts +2 -2
- package/crud/contentModelGroup/beforeDelete.js +3 -11
- package/crud/contentModelGroup/beforeDelete.js.map +1 -1
- package/crud/contentModelGroup/beforeUpdate.d.ts +2 -2
- package/crud/contentModelGroup/beforeUpdate.js +2 -7
- 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 +96 -118
- package/crud/contentModelGroup.crud.js.map +1 -1
- package/crud/settings.crud.js +3 -20
- package/crud/settings.crud.js.map +1 -1
- package/crud/system.crud.js +61 -84
- package/crud/system.crud.js.map +1 -1
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +1 -14
- 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 +16 -71
- 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 +91 -75
- 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 +14 -22
- 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 +40 -66
- 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 +57 -21
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createFieldResolvers.d.ts +1 -1
- package/graphql/schema/createFieldResolvers.js +24 -37
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/graphql/schema/createManageResolvers.js +4 -44
- package/graphql/schema/createManageResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.d.ts +2 -0
- package/graphql/schema/createManageSDL.js +13 -26
- package/graphql/schema/createManageSDL.js.map +1 -1
- package/graphql/schema/createPreviewResolvers.js +3 -17
- package/graphql/schema/createPreviewResolvers.js.map +1 -1
- package/graphql/schema/createReadResolvers.js +8 -17
- package/graphql/schema/createReadResolvers.js.map +1 -1
- package/graphql/schema/createReadSDL.d.ts +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 +5 -25
- 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 +3 -15
- 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 +3 -15
- 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 +4 -12
- package/graphqlFields/number.js.map +1 -1
- package/graphqlFields/object.js +113 -99
- package/graphqlFields/object.js.map +1 -1
- package/graphqlFields/ref.js +52 -104
- 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.d.ts +7 -7
- package/modelManager/DefaultCmsModelManager.js +1 -17
- package/modelManager/DefaultCmsModelManager.js.map +1 -1
- package/modelManager/index.js +0 -4
- package/modelManager/index.js.map +1 -1
- package/package.json +31 -32
- package/parameters/context.js +0 -4
- package/parameters/context.js.map +1 -1
- package/parameters/header.js +1 -12
- package/parameters/header.js.map +1 -1
- package/parameters/index.js +0 -8
- package/parameters/index.js.map +1 -1
- package/parameters/manual.js +7 -15
- package/parameters/manual.js.map +1 -1
- package/parameters/path.js +1 -12
- 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 +1 -9
- package/plugins/CmsGroupPlugin.js.map +1 -1
- package/plugins/CmsModelFieldConverterPlugin.d.ts +2 -2
- package/plugins/CmsModelFieldConverterPlugin.js +1 -6
- package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
- package/plugins/CmsModelPlugin.d.ts +6 -2
- package/plugins/CmsModelPlugin.js +18 -49
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/plugins/CmsParametersPlugin.js +1 -8
- package/plugins/CmsParametersPlugin.js.map +1 -1
- package/plugins/StorageTransformPlugin.d.ts +11 -11
- package/plugins/StorageTransformPlugin.js +1 -10
- 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 +7 -27
- package/storage/object.js.map +1 -1
- package/types.d.ts +504 -179
- package/types.js +62 -71
- package/types.js.map +1 -1
- package/upgrades/5.33.0/index.js +8 -35
- 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 +1 -14
- package/utils/converters/Converter.js.map +1 -1
- package/utils/converters/ConverterCollection.d.ts +7 -0
- package/utils/converters/ConverterCollection.js +36 -32
- package/utils/converters/ConverterCollection.js.map +1 -1
- package/utils/converters/valueKeyStorageConverter.js +3 -33
- 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 +3 -10
- package/utils/createTypeName.js.map +1 -1
- package/utils/entryStorage.js +25 -42
- 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 +7 -26
- package/utils/permissions.js.map +1 -1
- package/utils/pluralizedTypeName.js +1 -7
- 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 +10 -9
- 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 +1 -5
- 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 +1 -8
- package/validators/unique.js.map +1 -1
- package/crud/index.d.ts +0 -6
- package/crud/index.js +0 -89
- 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 -81
- package/utils/filterModelFields.js.map +0 -1
|
@@ -1,22 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.markUnlockedFields = exports.markLockedFields = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
8
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
12
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
-
|
|
14
10
|
var _CmsModelPlugin = require("../../plugins/CmsModelPlugin");
|
|
15
|
-
|
|
16
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
17
|
-
|
|
18
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
19
|
-
|
|
11
|
+
var _getBaseFieldType = require("../../utils/getBaseFieldType");
|
|
20
12
|
const markLockedFields = async params => {
|
|
21
13
|
const {
|
|
22
14
|
model,
|
|
@@ -25,67 +17,58 @@ const markLockedFields = async params => {
|
|
|
25
17
|
/**
|
|
26
18
|
* If the model is registered via a plugin, we don't need do process anything.
|
|
27
19
|
*/
|
|
28
|
-
|
|
29
20
|
const plugins = context.plugins.byType(_CmsModelPlugin.CmsModelPlugin.type);
|
|
30
|
-
|
|
31
21
|
if (plugins.find(plugin => plugin.contentModel.modelId === model.modelId)) {
|
|
32
22
|
return;
|
|
33
23
|
}
|
|
34
|
-
|
|
35
24
|
const cmsLockedFieldPlugins = context.plugins.byType("cms-model-locked-field");
|
|
36
25
|
const existingLockedFields = model.lockedFields || [];
|
|
37
26
|
const lockedFields = [];
|
|
38
|
-
|
|
39
27
|
for (const field of model.fields) {
|
|
28
|
+
const baseType = (0, _getBaseFieldType.getBaseFieldType)(field);
|
|
40
29
|
const alreadyLocked = existingLockedFields.some(lockedField => lockedField.fieldId === field.storageId);
|
|
41
|
-
|
|
42
30
|
if (alreadyLocked) {
|
|
43
31
|
continue;
|
|
44
32
|
}
|
|
45
|
-
|
|
46
33
|
let lockedFieldData = {};
|
|
47
|
-
const lockedFieldPlugins = cmsLockedFieldPlugins.filter(pl => pl.fieldType ===
|
|
48
|
-
|
|
34
|
+
const lockedFieldPlugins = cmsLockedFieldPlugins.filter(pl => pl.fieldType === baseType);
|
|
49
35
|
for (const plugin of lockedFieldPlugins) {
|
|
50
36
|
if (typeof plugin.getLockedFieldData !== "function") {
|
|
51
37
|
continue;
|
|
52
38
|
}
|
|
53
|
-
|
|
54
39
|
const data = plugin.getLockedFieldData({
|
|
55
40
|
field
|
|
56
41
|
});
|
|
57
|
-
lockedFieldData =
|
|
42
|
+
lockedFieldData = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, lockedFieldData), data);
|
|
58
43
|
}
|
|
59
|
-
|
|
60
|
-
lockedFields.push(_objectSpread({
|
|
44
|
+
lockedFields.push((0, _objectSpread2.default)({
|
|
61
45
|
fieldId: field.storageId,
|
|
62
46
|
multipleValues: !!field.multipleValues,
|
|
63
|
-
type:
|
|
47
|
+
type: baseType
|
|
64
48
|
}, lockedFieldData));
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
49
|
+
}
|
|
50
|
+
// no need to update anything if no locked fields were added
|
|
68
51
|
if (lockedFields.length === 0) {
|
|
69
52
|
return;
|
|
70
53
|
}
|
|
71
|
-
|
|
72
54
|
const newLockedFields = existingLockedFields.concat(lockedFields);
|
|
73
|
-
|
|
74
55
|
try {
|
|
75
56
|
await context.cms.updateModelDirect({
|
|
76
57
|
original: model,
|
|
77
|
-
model:
|
|
58
|
+
model: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, model), {}, {
|
|
78
59
|
lockedFields: newLockedFields
|
|
79
60
|
})
|
|
80
61
|
});
|
|
81
62
|
model.lockedFields = newLockedFields;
|
|
82
63
|
} catch (ex) {
|
|
83
|
-
throw new _error.default(`Could not update model "${model.modelId}" with new locked fields.`, "MODEL_LOCKED_FIELDS_UPDATE_FAILED",
|
|
64
|
+
throw new _error.default(`Could not update model "${model.modelId}" with new locked fields.`, "MODEL_LOCKED_FIELDS_UPDATE_FAILED", {
|
|
65
|
+
message: ex.message,
|
|
66
|
+
code: ex.code,
|
|
67
|
+
data: ex.data
|
|
68
|
+
});
|
|
84
69
|
}
|
|
85
70
|
};
|
|
86
|
-
|
|
87
71
|
exports.markLockedFields = markLockedFields;
|
|
88
|
-
|
|
89
72
|
const markUnlockedFields = async params => {
|
|
90
73
|
const {
|
|
91
74
|
context,
|
|
@@ -94,24 +77,24 @@ const markUnlockedFields = async params => {
|
|
|
94
77
|
/**
|
|
95
78
|
* If the model is registered via a plugin, we don't need do process anything.
|
|
96
79
|
*/
|
|
97
|
-
|
|
98
80
|
const plugins = context.plugins.byType(_CmsModelPlugin.CmsModelPlugin.type);
|
|
99
|
-
|
|
100
81
|
if (plugins.find(plugin => plugin.contentModel.modelId === model.modelId)) {
|
|
101
82
|
return;
|
|
102
83
|
}
|
|
103
|
-
|
|
104
84
|
try {
|
|
105
85
|
await context.cms.updateModelDirect({
|
|
106
86
|
original: model,
|
|
107
|
-
model:
|
|
87
|
+
model: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, model), {}, {
|
|
108
88
|
lockedFields: []
|
|
109
89
|
})
|
|
110
90
|
});
|
|
111
91
|
model.lockedFields = [];
|
|
112
92
|
} catch (ex) {
|
|
113
|
-
throw new _error.default(`Could not update model "${model.modelId}" with unlocked fields.`, "MODEL_UNLOCKED_FIELDS_UPDATE_FAILED",
|
|
93
|
+
throw new _error.default(`Could not update model "${model.modelId}" with unlocked fields.`, "MODEL_UNLOCKED_FIELDS_UPDATE_FAILED", {
|
|
94
|
+
message: ex.message,
|
|
95
|
+
code: ex.code,
|
|
96
|
+
data: ex.data
|
|
97
|
+
});
|
|
114
98
|
}
|
|
115
99
|
};
|
|
116
|
-
|
|
117
100
|
exports.markUnlockedFields = markUnlockedFields;
|
|
@@ -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;AACJ;AACA;EACI,MAAMG,OAAO,GAAGD,OAAO,CAACC,OAAO,CAACC,MAAM,CAAiBC,8BAAc,CAACC,IAAI,CAAC;EAC3E,IAAIH,OAAO,CAACI,IAAI,CAACC,MAAM,IAAIA,MAAM,CAACC,YAAY,CAACC,OAAO,KAAKT,KAAK,CAACS,OAAO,CAAC,EAAE;IACvE;EACJ;EAEA,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
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.referenceFieldsMapping = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
8
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
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
|
-
|
|
18
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
19
|
-
|
|
20
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
21
|
-
|
|
12
|
+
var _getBaseFieldType = require("../../utils/getBaseFieldType");
|
|
22
13
|
const buildReferenceFieldPaths = params => {
|
|
23
14
|
const {
|
|
24
15
|
fields,
|
|
@@ -27,77 +18,61 @@ const buildReferenceFieldPaths = params => {
|
|
|
27
18
|
} = params;
|
|
28
19
|
const parentPaths = [...initialParentPaths];
|
|
29
20
|
const isMultipleValues = Array.isArray(input);
|
|
30
|
-
return fields.filter(field => ["object", "ref"].includes(
|
|
21
|
+
return fields.filter(field => ["object", "ref"].includes((0, _getBaseFieldType.getBaseFieldType)(field))).reduce((collection, field) => {
|
|
31
22
|
var _field$settings2;
|
|
32
|
-
|
|
33
23
|
/**
|
|
34
24
|
* First we check the ref field
|
|
35
25
|
*/
|
|
36
|
-
|
|
26
|
+
const baseType = (0, _getBaseFieldType.getBaseFieldType)(field);
|
|
27
|
+
if (baseType === "ref") {
|
|
37
28
|
const parentPathsValue = parentPaths.length > 0 ? `${parentPaths.join(".")}.` : "";
|
|
38
|
-
|
|
39
29
|
if (field.multipleValues) {
|
|
40
30
|
const inputValue = _dotProp.default.get(input, `${field.fieldId}`, []);
|
|
41
|
-
|
|
42
31
|
if (Array.isArray(inputValue) === false) {
|
|
43
32
|
return collection;
|
|
44
33
|
}
|
|
45
|
-
|
|
46
34
|
for (const key in inputValue) {
|
|
47
35
|
const path = `${parentPathsValue}${field.fieldId}.${key}`;
|
|
48
36
|
collection.push(path);
|
|
49
37
|
}
|
|
50
|
-
|
|
51
38
|
return collection;
|
|
52
39
|
}
|
|
53
|
-
|
|
54
40
|
if (isMultipleValues) {
|
|
55
41
|
for (const key in input) {
|
|
56
42
|
const path = `${parentPathsValue}${key}.${field.fieldId}`;
|
|
57
43
|
collection.push(path);
|
|
58
44
|
}
|
|
59
|
-
|
|
60
45
|
return collection;
|
|
61
46
|
}
|
|
62
|
-
|
|
63
47
|
collection.push(`${parentPathsValue}${field.fieldId}`);
|
|
64
48
|
return collection;
|
|
65
49
|
}
|
|
66
50
|
/**
|
|
67
51
|
* Then we move onto the object field
|
|
68
52
|
*/
|
|
69
|
-
|
|
70
|
-
|
|
71
53
|
const parentPathsValue = parentPaths.length > 0 ? `${parentPaths.join(".")}.` : "";
|
|
72
54
|
/**
|
|
73
55
|
* This is if received input is array. We need to map key with fieldId at this point.
|
|
74
56
|
*/
|
|
75
|
-
|
|
76
57
|
if (isMultipleValues) {
|
|
77
58
|
for (const key in input) {
|
|
78
59
|
const path = `${parentPathsValue}${key}.${field.fieldId}`;
|
|
79
60
|
collection.push(path);
|
|
80
61
|
}
|
|
81
|
-
|
|
82
62
|
return collection;
|
|
83
63
|
}
|
|
84
|
-
|
|
85
64
|
const objFieldPath = `${field.fieldId}`;
|
|
86
|
-
|
|
87
65
|
const objFieldInputValue = _dotProp.default.get(input, objFieldPath, []);
|
|
66
|
+
|
|
88
67
|
/**
|
|
89
68
|
* If field is multiple values one, we need to go through the input and use the existing keys.
|
|
90
69
|
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
70
|
if (field.multipleValues) {
|
|
94
71
|
if (Array.isArray(objFieldInputValue) === false) {
|
|
95
72
|
return collection;
|
|
96
73
|
}
|
|
97
|
-
|
|
98
74
|
for (const key in objFieldInputValue) {
|
|
99
75
|
var _field$settings;
|
|
100
|
-
|
|
101
76
|
const result = buildReferenceFieldPaths({
|
|
102
77
|
fields: ((_field$settings = field.settings) === null || _field$settings === void 0 ? void 0 : _field$settings.fields) || [],
|
|
103
78
|
input: objFieldInputValue[key],
|
|
@@ -105,14 +80,12 @@ const buildReferenceFieldPaths = params => {
|
|
|
105
80
|
});
|
|
106
81
|
collection.push(...result);
|
|
107
82
|
}
|
|
108
|
-
|
|
109
83
|
return collection;
|
|
110
84
|
}
|
|
85
|
+
|
|
111
86
|
/**
|
|
112
87
|
* Single value reference field.
|
|
113
88
|
*/
|
|
114
|
-
|
|
115
|
-
|
|
116
89
|
const results = buildReferenceFieldPaths({
|
|
117
90
|
fields: ((_field$settings2 = field.settings) === null || _field$settings2 === void 0 ? void 0 : _field$settings2.fields) || [],
|
|
118
91
|
input: objFieldInputValue,
|
|
@@ -121,7 +94,6 @@ const buildReferenceFieldPaths = params => {
|
|
|
121
94
|
return collection.concat(results);
|
|
122
95
|
}, []);
|
|
123
96
|
};
|
|
124
|
-
|
|
125
97
|
const getReferenceFieldValue = ref => {
|
|
126
98
|
if (!ref) {
|
|
127
99
|
return {
|
|
@@ -129,13 +101,11 @@ const getReferenceFieldValue = ref => {
|
|
|
129
101
|
modelId: null
|
|
130
102
|
};
|
|
131
103
|
}
|
|
132
|
-
|
|
133
104
|
return {
|
|
134
105
|
id: (ref.id || ref.entryId || "").trim() || null,
|
|
135
106
|
modelId: (ref.modelId || "").trim() || null
|
|
136
107
|
};
|
|
137
108
|
};
|
|
138
|
-
|
|
139
109
|
const referenceFieldsMapping = async params => {
|
|
140
110
|
const {
|
|
141
111
|
context,
|
|
@@ -143,80 +113,62 @@ const referenceFieldsMapping = async params => {
|
|
|
143
113
|
input,
|
|
144
114
|
validateEntries = false
|
|
145
115
|
} = params;
|
|
146
|
-
|
|
147
|
-
let output = _objectSpread({}, input);
|
|
148
|
-
|
|
116
|
+
let output = (0, _objectSpread2.default)({}, input);
|
|
149
117
|
const referenceFieldPaths = buildReferenceFieldPaths({
|
|
150
118
|
fields: model.fields,
|
|
151
119
|
input,
|
|
152
120
|
parentPaths: []
|
|
153
121
|
});
|
|
154
|
-
|
|
155
122
|
if (referenceFieldPaths.length === 0) {
|
|
156
123
|
return output;
|
|
157
124
|
}
|
|
158
|
-
|
|
159
125
|
const referencesByModel = {};
|
|
160
126
|
const pathsByReferenceId = {};
|
|
161
|
-
|
|
162
127
|
for (const path of referenceFieldPaths) {
|
|
163
128
|
const ref = _dotProp.default.get(output, path);
|
|
164
|
-
|
|
165
129
|
const {
|
|
166
130
|
id,
|
|
167
131
|
modelId
|
|
168
132
|
} = getReferenceFieldValue(ref);
|
|
169
|
-
|
|
170
133
|
if (!id || !modelId) {
|
|
171
134
|
continue;
|
|
172
135
|
}
|
|
173
|
-
|
|
174
136
|
if (!referencesByModel[modelId]) {
|
|
175
137
|
referencesByModel[modelId] = [];
|
|
176
138
|
}
|
|
177
|
-
|
|
178
139
|
referencesByModel[modelId].push(id);
|
|
179
|
-
|
|
180
140
|
if (!pathsByReferenceId[id]) {
|
|
181
141
|
pathsByReferenceId[id] = [];
|
|
182
142
|
}
|
|
183
|
-
|
|
184
143
|
pathsByReferenceId[id].push(path);
|
|
185
144
|
}
|
|
145
|
+
|
|
186
146
|
/**
|
|
187
147
|
* Again, no point in going further.
|
|
188
148
|
*/
|
|
189
|
-
|
|
190
|
-
|
|
191
149
|
if (Object.keys(referencesByModel).length === 0) {
|
|
192
150
|
return output;
|
|
193
151
|
}
|
|
194
152
|
/**
|
|
195
153
|
* Load all models and use only those that are used in reference.
|
|
196
154
|
*/
|
|
197
|
-
|
|
198
|
-
|
|
199
155
|
const models = (await context.cms.listModels()).filter(model => {
|
|
200
156
|
const entries = referencesByModel[model.modelId];
|
|
201
|
-
|
|
202
|
-
if (Array.isArray(entries) === false || entries.length === 0) {
|
|
157
|
+
if (!Array.isArray(entries) || entries.length === 0) {
|
|
203
158
|
return false;
|
|
204
159
|
}
|
|
205
|
-
|
|
206
160
|
return true;
|
|
207
161
|
});
|
|
208
162
|
/**
|
|
209
163
|
* Check for any model existence, just in case.
|
|
210
164
|
*/
|
|
211
|
-
|
|
212
165
|
if (models.length === 0) {
|
|
213
166
|
return output;
|
|
214
167
|
}
|
|
168
|
+
|
|
215
169
|
/**
|
|
216
170
|
* Load all the entries by their ID
|
|
217
171
|
*/
|
|
218
|
-
|
|
219
|
-
|
|
220
172
|
const promises = models.map(model => {
|
|
221
173
|
return context.cms.getEntriesByIds(model, referencesByModel[model.modelId]);
|
|
222
174
|
});
|
|
@@ -229,26 +181,22 @@ const referenceFieldsMapping = async params => {
|
|
|
229
181
|
modelId: entry.modelId
|
|
230
182
|
};
|
|
231
183
|
}
|
|
232
|
-
|
|
233
184
|
return collection;
|
|
234
185
|
}, {});
|
|
235
186
|
/**
|
|
236
187
|
* Verify that all referenced entries actually exist.
|
|
237
188
|
*/
|
|
238
|
-
|
|
239
189
|
for (const modelId in referencesByModel) {
|
|
240
190
|
const entries = referencesByModel[modelId];
|
|
241
|
-
|
|
242
191
|
for (const id of entries) {
|
|
243
192
|
if (records[id]) {
|
|
244
193
|
continue;
|
|
245
|
-
} else if (validateEntries
|
|
194
|
+
} else if (validateEntries) {
|
|
246
195
|
throw new _error.default(`Missing referenced entry with id "${id}" in model "${modelId}".`, "ENTRY_NOT_FOUND", {
|
|
247
196
|
id,
|
|
248
197
|
model: modelId
|
|
249
198
|
});
|
|
250
199
|
}
|
|
251
|
-
|
|
252
200
|
const {
|
|
253
201
|
id: entryId
|
|
254
202
|
} = (0, _utils.parseIdentifier)(id);
|
|
@@ -259,26 +207,22 @@ const referenceFieldsMapping = async params => {
|
|
|
259
207
|
};
|
|
260
208
|
}
|
|
261
209
|
}
|
|
210
|
+
|
|
262
211
|
/**
|
|
263
212
|
* In the end, assign the entryId, id and model values to the output.
|
|
264
213
|
*/
|
|
265
|
-
|
|
266
|
-
|
|
267
214
|
for (const id in pathsByReferenceId) {
|
|
268
215
|
const entry = records[id];
|
|
269
216
|
const paths = pathsByReferenceId[id];
|
|
270
|
-
|
|
271
217
|
if (!entry) {
|
|
272
|
-
if (validateEntries
|
|
218
|
+
if (validateEntries) {
|
|
273
219
|
throw new _error.default("Missing entry in records.", "ENTRY_ERROR", {
|
|
274
220
|
id,
|
|
275
221
|
paths
|
|
276
222
|
});
|
|
277
223
|
}
|
|
278
|
-
|
|
279
224
|
continue;
|
|
280
225
|
}
|
|
281
|
-
|
|
282
226
|
for (const path of paths) {
|
|
283
227
|
output = _dotProp.default.set(output, path, {
|
|
284
228
|
id: entry.id,
|
|
@@ -287,8 +231,6 @@ const referenceFieldsMapping = async params => {
|
|
|
287
231
|
});
|
|
288
232
|
}
|
|
289
233
|
}
|
|
290
|
-
|
|
291
234
|
return output;
|
|
292
235
|
};
|
|
293
|
-
|
|
294
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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ACD,MAAM;QAAED,EAAE,EAAEE;MAAN,IAAkB,IAAAwB,sBAAA,EAAgB1B,EAAhB,CAAxB;MACAuB,OAAO,CAACvB,EAAD,CAAP,GAAc;QACVA,EADU;QAEVE,OAFU;QAGVD;MAHU,CAAd;IAKH;EACJ;EAED;AACJ;AACA;;;EACI,KAAK,MAAMD,EAAX,IAAiBW,kBAAjB,EAAqC;IACjC,MAAMa,KAAK,GAAGD,OAAO,CAACvB,EAAD,CAArB;IACA,MAAM2B,KAAK,GAAGhB,kBAAkB,CAACX,EAAD,CAAhC;;IACA,IAAI,CAACwB,KAAL,EAAY;MACR,IAAIjB,eAAe,KAAK,IAAxB,EAA8B;QAC1B,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"}
|
|
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,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AC;IACzB,MAAM2B,KAAK,GAAGhB,kBAAkB,CAACX,EAAE,CAAC;IACpC,IAAI,CAACwB,KAAK,EAAE;MACR,IAAIjB,eAAe,EAAE;QACjB,MAAM,IAAIkB,cAAW,CAAC,2BAA2B,EAAE,aAAa,EAAE;UAC9DzB,EAAE;UACF2B;QACJ,CAAC,CAAC;MACN;MACA;IACJ;IACA,KAAK,MAAMrC,IAAI,IAAIqC,KAAK,EAAE;MACtBnB,MAAM,GAAGtB,gBAAO,CAAC0C,GAAG,CAACpB,MAAM,EAAElB,IAAI,EAAE;QAC/BU,EAAE,EAAEwB,KAAK,CAACxB,EAAE;QACZE,OAAO,EAAEsB,KAAK,CAACtB,OAAO;QACtBD,OAAO,EAAEuB,KAAK,CAACvB;MACnB,CAAC,CAAC;IACN;EACJ;EAEA,OAAOO,MAAM;AACjB,CAAC;AAAC"}
|
|
@@ -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,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,G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ClEhB,MAAM,CAAC,CAACiB,UAAU,EAAEf,KAAK,KAAK;IAC3Be,UAAU,CAACf,KAAK,CAACgB,SAAS,CAAC,GAAGhB,KAAK;IACnC,OAAOe,UAAU;EACrB,CAAC,EAAE,CAAC,CAAC,CAAiD;EAE1D,OAAOvB,wBAAwB,CAAC;IAC5BI,MAAM;IACNF,KAAK;IACLC,OAAO,EAAEkB,cAAc;IACvBhB,OAAO,EAAE;EACb,CAAC,CAAC;AACN,CAAC;AAAC"}
|
|
@@ -4,8 +4,6 @@ import { Tenant } from "@webiny/api-tenancy/types";
|
|
|
4
4
|
export declare const STATUS_DRAFT = "draft";
|
|
5
5
|
export declare const STATUS_PUBLISHED = "published";
|
|
6
6
|
export declare const STATUS_UNPUBLISHED = "unpublished";
|
|
7
|
-
export declare const STATUS_CHANGES_REQUESTED = "changesRequested";
|
|
8
|
-
export declare const STATUS_REVIEW_REQUESTED = "reviewRequested";
|
|
9
7
|
export interface CreateContentEntryCrudParams {
|
|
10
8
|
storageOperations: HeadlessCmsStorageOperations;
|
|
11
9
|
context: CmsContext;
|