@webiny/api-headless-cms 0.0.0-unstable.3386f66516 → 0.0.0-unstable.496cf268ac
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.js +0 -25
- package/context.js.map +1 -1
- package/crud/contentEntry/afterDelete.js +0 -5
- package/crud/contentEntry/afterDelete.js.map +1 -1
- package/crud/contentEntry/beforeCreate.js +0 -3
- package/crud/contentEntry/beforeCreate.js.map +1 -1
- package/crud/contentEntry/beforeUpdate.js +0 -3
- package/crud/contentEntry/beforeUpdate.js.map +1 -1
- package/crud/contentEntry/entryDataValidation.js +1 -40
- package/crud/contentEntry/entryDataValidation.js.map +1 -1
- package/crud/contentEntry/markLockedFields.d.ts +1 -1
- package/crud/contentEntry/markLockedFields.js +15 -28
- package/crud/contentEntry/markLockedFields.js.map +1 -1
- package/crud/contentEntry/referenceFieldsMapping.js +5 -61
- package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
- package/crud/contentEntry/searchableFields.js +1 -12
- package/crud/contentEntry/searchableFields.js.map +1 -1
- package/crud/contentEntry.crud.d.ts +2 -1
- package/crud/contentEntry.crud.js +59 -166
- 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.js +7 -32
- 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.js +4 -5
- package/crud/contentModel/beforeUpdate.js.map +1 -1
- package/crud/contentModel/compatibility/modelApiName.d.ts +3 -0
- package/crud/contentModel/compatibility/modelApiName.js +24 -0
- package/crud/contentModel/compatibility/modelApiName.js.map +1 -0
- package/crud/contentModel/contentModelManagerFactory.js +0 -7
- package/crud/contentModel/contentModelManagerFactory.js.map +1 -1
- package/crud/contentModel/createFieldStorageId.js +0 -3
- package/crud/contentModel/createFieldStorageId.js.map +1 -1
- package/crud/contentModel/defaultFields.d.ts +5 -0
- package/crud/contentModel/defaultFields.js +58 -0
- package/crud/contentModel/defaultFields.js.map +1 -0
- package/crud/contentModel/fields/descriptionField.d.ts +2 -0
- package/crud/contentModel/fields/descriptionField.js +42 -0
- package/crud/contentModel/fields/descriptionField.js.map +1 -0
- package/crud/contentModel/fields/imageField.d.ts +2 -0
- package/crud/contentModel/fields/imageField.js +46 -0
- package/crud/contentModel/fields/imageField.js.map +1 -0
- package/crud/contentModel/fields/titleField.d.ts +2 -0
- package/crud/contentModel/fields/titleField.js +58 -0
- package/crud/contentModel/fields/titleField.js.map +1 -0
- package/crud/contentModel/validateLayout.js +0 -8
- package/crud/contentModel/validateLayout.js.map +1 -1
- package/crud/contentModel/validateModel.d.ts +1 -0
- package/crud/contentModel/validateModel.js +0 -8
- package/crud/contentModel/validateModel.js.map +1 -1
- package/crud/contentModel/validateModelFields.d.ts +2 -1
- package/crud/contentModel/validateModelFields.js +35 -128
- package/crud/contentModel/validateModelFields.js.map +1 -1
- package/crud/contentModel/validation.d.ts +85 -43
- package/crud/contentModel/validation.js +57 -21
- package/crud/contentModel/validation.js.map +1 -1
- package/crud/contentModel.crud.js +46 -110
- 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.js +0 -9
- package/crud/contentModelGroup/validation.js.map +1 -1
- package/crud/contentModelGroup.crud.js +5 -47
- 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 +1 -96
- package/crud/system.crud.js.map +1 -1
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +0 -13
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +0 -36
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +0 -53
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/index.js +0 -5
- package/fieldConverters/index.js.map +1 -1
- package/graphql/buildSchemaPlugins.js +4 -9
- package/graphql/buildSchemaPlugins.js.map +1 -1
- package/graphql/createExecutableSchema.js +2 -6
- package/graphql/createExecutableSchema.js.map +1 -1
- package/graphql/generateSchema.js +0 -7
- package/graphql/generateSchema.js.map +1 -1
- package/graphql/graphQLHandlerFactory.js +16 -39
- package/graphql/graphQLHandlerFactory.js.map +1 -1
- package/graphql/index.js +0 -5
- package/graphql/index.js.map +1 -1
- package/graphql/schema/baseContentSchema.js +5 -17
- package/graphql/schema/baseContentSchema.js.map +1 -1
- package/graphql/schema/baseSchema.js +1 -8
- package/graphql/schema/baseSchema.js.map +1 -1
- package/graphql/schema/contentEntries.js +107 -102
- package/graphql/schema/contentEntries.js.map +1 -1
- package/graphql/schema/contentModelGroups.js +3 -20
- package/graphql/schema/contentModelGroups.js.map +1 -1
- package/graphql/schema/contentModels.js +22 -25
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createFieldResolvers.js +5 -28
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/graphql/schema/createManageResolvers.d.ts +1 -1
- package/graphql/schema/createManageResolvers.js +33 -43
- package/graphql/schema/createManageResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.d.ts +1 -0
- package/graphql/schema/createManageSDL.js +57 -63
- 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 +4 -18
- package/graphql/schema/createReadResolvers.js.map +1 -1
- package/graphql/schema/createReadSDL.d.ts +1 -0
- package/graphql/schema/createReadSDL.js +24 -32
- package/graphql/schema/createReadSDL.js.map +1 -1
- package/graphql/schema/resolvers/commonFieldResolvers.d.ts +3 -2
- package/graphql/schema/resolvers/commonFieldResolvers.js +2 -3
- package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveCreate.js +0 -3
- package/graphql/schema/resolvers/manage/resolveCreate.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveCreateFrom.js +0 -3
- package/graphql/schema/resolvers/manage/resolveCreateFrom.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveDelete.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.js +16 -26
- package/graphql/schema/schemaPlugins.js.map +1 -1
- package/graphql/system.js +1 -30
- 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.js +15 -33
- package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js +2 -18
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js.map +1 -1
- package/graphqlFields/dynamicZone/index.js +0 -2
- package/graphqlFields/dynamicZone/index.js.map +1 -1
- package/graphqlFields/file.js +0 -8
- package/graphqlFields/file.js.map +1 -1
- package/graphqlFields/helpers.js +0 -10
- package/graphqlFields/helpers.js.map +1 -1
- package/graphqlFields/index.js +0 -12
- package/graphqlFields/index.js.map +1 -1
- package/graphqlFields/longText.js +0 -10
- package/graphqlFields/longText.js.map +1 -1
- package/graphqlFields/number.js +0 -12
- package/graphqlFields/number.js.map +1 -1
- package/graphqlFields/object.js +7 -37
- package/graphqlFields/object.js.map +1 -1
- package/graphqlFields/ref.js +59 -65
- 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 +1 -1
- package/index.js +1 -21
- 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 +24 -25
- 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.js +0 -5
- package/plugins/CmsGraphQLSchemaPlugin.js.map +1 -1
- package/plugins/CmsGraphQLSchemaSorterPlugin.js +0 -10
- package/plugins/CmsGraphQLSchemaSorterPlugin.js.map +1 -1
- package/plugins/CmsGroupPlugin.js +0 -8
- package/plugins/CmsGroupPlugin.js.map +1 -1
- package/plugins/CmsModelFieldConverterPlugin.js +0 -5
- package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
- package/plugins/CmsModelPlugin.d.ts +11 -1
- package/plugins/CmsModelPlugin.js +15 -40
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/plugins/CmsParametersPlugin.js +0 -7
- package/plugins/CmsParametersPlugin.js.map +1 -1
- package/plugins/StorageTransformPlugin.js +0 -9
- package/plugins/StorageTransformPlugin.js.map +1 -1
- package/plugins/index.js +0 -14
- package/plugins/index.js.map +1 -1
- package/storage/default.js +0 -3
- package/storage/default.js.map +1 -1
- package/storage/object.js +0 -19
- package/storage/object.js.map +1 -1
- package/types.d.ts +77 -22
- package/types.js +1 -80
- package/types.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 +9 -33
- package/utils/converters/ConverterCollection.js.map +1 -1
- package/utils/converters/valueKeyStorageConverter.js +2 -27
- package/utils/converters/valueKeyStorageConverter.js.map +1 -1
- package/utils/createTypeFromFields.d.ts +1 -0
- package/utils/createTypeFromFields.js +11 -19
- package/utils/createTypeFromFields.js.map +1 -1
- package/utils/createTypeName.js +0 -9
- package/utils/createTypeName.js.map +1 -1
- package/utils/entryStorage.js +10 -26
- package/utils/entryStorage.js.map +1 -1
- package/utils/filterAsync.js +0 -5
- package/utils/filterAsync.js.map +1 -1
- package/utils/getBaseFieldType.js +0 -2
- package/utils/getBaseFieldType.js.map +1 -1
- package/utils/getEntryDescription.d.ts +2 -0
- package/utils/getEntryDescription.js +17 -0
- package/utils/getEntryDescription.js.map +1 -0
- package/utils/getEntryImage.d.ts +2 -0
- package/utils/getEntryImage.js +17 -0
- package/utils/getEntryImage.js.map +1 -0
- package/utils/getEntryTitle.js +0 -9
- package/utils/getEntryTitle.js.map +1 -1
- package/utils/getSchemaFromFieldPlugins.js +2 -11
- package/utils/getSchemaFromFieldPlugins.js.map +1 -1
- package/utils/ownership.d.ts +3 -3
- 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/removeNullValues.d.ts +1 -0
- package/utils/removeNullValues.js +17 -0
- package/utils/removeNullValues.js.map +1 -0
- package/utils/removeUndefinedValues.d.ts +1 -0
- package/utils/removeUndefinedValues.js +17 -0
- package/utils/removeUndefinedValues.js.map +1 -0
- package/utils/renderFields.d.ts +2 -1
- package/utils/renderFields.js +8 -10
- package/utils/renderFields.js.map +1 -1
- package/utils/renderGetFilterFields.js +0 -13
- package/utils/renderGetFilterFields.js.map +1 -1
- package/utils/renderInputFields.d.ts +2 -1
- package/utils/renderInputFields.js +4 -9
- package/utils/renderInputFields.js.map +1 -1
- package/utils/renderListFilterFields.js +1 -10
- package/utils/renderListFilterFields.js.map +1 -1
- package/utils/renderSortEnum.js +0 -9
- package/utils/renderSortEnum.js.map +1 -1
- package/utils/toSlug.js +0 -4
- package/utils/toSlug.js.map +1 -1
- package/validators/dateGte.js +0 -7
- package/validators/dateGte.js.map +1 -1
- package/validators/dateLte.js +0 -7
- package/validators/dateLte.js.map +1 -1
- package/validators/dynamicZone.js +0 -4
- package/validators/dynamicZone.js.map +1 -1
- package/validators/gte.js +0 -8
- package/validators/gte.js.map +1 -1
- package/validators/in.js +0 -8
- package/validators/in.js.map +1 -1
- package/validators/index.js +0 -16
- package/validators/index.js.map +1 -1
- package/validators/lte.js +0 -8
- package/validators/lte.js.map +1 -1
- package/validators/maxLength.js +0 -8
- package/validators/maxLength.js.map +1 -1
- package/validators/minLength.js +0 -8
- package/validators/minLength.js.map +1 -1
- package/validators/pattern.js +0 -9
- package/validators/pattern.js.map +1 -1
- package/validators/patternPlugins/email.js +0 -2
- package/validators/patternPlugins/email.js.map +1 -1
- package/validators/patternPlugins/index.js +0 -8
- package/validators/patternPlugins/index.js.map +1 -1
- package/validators/patternPlugins/lowerCase.js +0 -2
- package/validators/patternPlugins/lowerCase.js.map +1 -1
- package/validators/patternPlugins/lowerCaseSpace.js +0 -2
- package/validators/patternPlugins/lowerCaseSpace.js.map +1 -1
- package/validators/patternPlugins/upperCase.js +0 -2
- package/validators/patternPlugins/upperCase.js.map +1 -1
- package/validators/patternPlugins/upperCaseSpace.js +0 -2
- package/validators/patternPlugins/upperCaseSpace.js.map +1 -1
- package/validators/patternPlugins/url.js +0 -2
- package/validators/patternPlugins/url.js.map +1 -1
- package/validators/required.js +0 -5
- package/validators/required.js.map +1 -1
- package/validators/timeGte.js +0 -8
- package/validators/timeGte.js.map +1 -1
- package/validators/timeLte.js +0 -8
- package/validators/timeLte.js.map +1 -1
- package/validators/unique.js +0 -7
- package/validators/unique.js.map +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getContentModelImageFieldId","fields","imageFieldId","length","imageField","find","field","getBaseFieldType","multipleValues","settings","imagesOnly","fieldId","target","WebinyError","storageId","type"],"sources":["imageField.ts"],"sourcesContent":["import { CmsModelField } from \"~/types\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\nimport WebinyError from \"@webiny/error\";\n\nexport const getContentModelImageFieldId = (\n fields: CmsModelField[],\n imageFieldId?: string | null\n): string | null | undefined => {\n /**\n * If there are no fields defined, we will just set as null.\n */\n if (fields.length === 0) {\n return null;\n }\n /**\n * If image field is not defined, let us find possible one.\n */\n if (!imageFieldId) {\n const imageField = fields.find(field => {\n return (\n getBaseFieldType(field) === \"file\" &&\n !field.multipleValues &&\n field.settings?.imagesOnly\n );\n });\n return imageField?.fieldId || null;\n }\n const target = fields.find(\n field =>\n field.fieldId === imageFieldId &&\n getBaseFieldType(field) === \"file\" &&\n field.settings?.imagesOnly\n );\n if (!target) {\n throw new WebinyError(\n `Field selected for the image field does not exist in the model.`,\n \"VALIDATION_ERROR\",\n {\n fieldId: imageFieldId,\n fields\n }\n );\n }\n if (target.multipleValues) {\n throw new WebinyError(\n `Fields that accept multiple values cannot be used as the entry image.`,\n \"ENTRY_TITLE_FIELD_TYPE\",\n {\n storageId: target.storageId,\n fieldId: target.fieldId,\n type: target.type\n }\n );\n }\n\n return target.fieldId;\n};\n"],"mappings":";;;;;;;AACA;AACA;AAEO,MAAMA,2BAA2B,GAAG,CACvCC,MAAuB,EACvBC,YAA4B,KACA;EAC5B;AACJ;AACA;EACI,IAAID,MAAM,CAACE,MAAM,KAAK,CAAC,EAAE;IACrB,OAAO,IAAI;EACf;EACA;AACJ;AACA;EACI,IAAI,CAACD,YAAY,EAAE;IACf,MAAME,UAAU,GAAGH,MAAM,CAACI,IAAI,CAACC,KAAK,IAAI;MAAA;MACpC,OACI,IAAAC,kCAAgB,EAACD,KAAK,CAAC,KAAK,MAAM,IAClC,CAACA,KAAK,CAACE,cAAc,wBACrBF,KAAK,CAACG,QAAQ,oDAAd,gBAAgBC,UAAU;IAElC,CAAC,CAAC;IACF,OAAO,CAAAN,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEO,OAAO,KAAI,IAAI;EACtC;EACA,MAAMC,MAAM,GAAGX,MAAM,CAACI,IAAI,CACtBC,KAAK;IAAA;IAAA,OACDA,KAAK,CAACK,OAAO,KAAKT,YAAY,IAC9B,IAAAK,kCAAgB,EAACD,KAAK,CAAC,KAAK,MAAM,yBAClCA,KAAK,CAACG,QAAQ,qDAAd,iBAAgBC,UAAU;EAAA,EACjC;EACD,IAAI,CAACE,MAAM,EAAE;IACT,MAAM,IAAIC,cAAW,CAChB,iEAAgE,EACjE,kBAAkB,EAClB;MACIF,OAAO,EAAET,YAAY;MACrBD;IACJ,CAAC,CACJ;EACL;EACA,IAAIW,MAAM,CAACJ,cAAc,EAAE;IACvB,MAAM,IAAIK,cAAW,CAChB,uEAAsE,EACvE,wBAAwB,EACxB;MACIC,SAAS,EAAEF,MAAM,CAACE,SAAS;MAC3BH,OAAO,EAAEC,MAAM,CAACD,OAAO;MACvBI,IAAI,EAAEH,MAAM,CAACG;IACjB,CAAC,CACJ;EACL;EAEA,OAAOH,MAAM,CAACD,OAAO;AACzB,CAAC;AAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getContentModelTitleFieldId = void 0;
|
|
8
|
+
var _getBaseFieldType = require("../../../utils/getBaseFieldType");
|
|
9
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
10
|
+
const defaultTitleFieldId = "id";
|
|
11
|
+
const allowedTitleFieldTypes = ["text", "number"];
|
|
12
|
+
const getContentModelTitleFieldId = (fields, titleFieldId) => {
|
|
13
|
+
/**
|
|
14
|
+
* If there are no fields defined, we will return the default field
|
|
15
|
+
*/
|
|
16
|
+
if (fields.length === 0) {
|
|
17
|
+
return defaultTitleFieldId;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* if there is no title field defined either in input data or existing content model data
|
|
21
|
+
* we will take first text field that has no multiple values enabled
|
|
22
|
+
* or if initial titleFieldId is the default one also try to find first available text field
|
|
23
|
+
*/
|
|
24
|
+
if (!titleFieldId || titleFieldId === defaultTitleFieldId) {
|
|
25
|
+
const titleField = fields.find(field => {
|
|
26
|
+
return (0, _getBaseFieldType.getBaseFieldType)(field) === "text" && !field.multipleValues;
|
|
27
|
+
});
|
|
28
|
+
return (titleField === null || titleField === void 0 ? void 0 : titleField.fieldId) || defaultTitleFieldId;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* check existing titleFieldId for existence in the model
|
|
32
|
+
* for correct type
|
|
33
|
+
* and that it is not multiple values field
|
|
34
|
+
*/
|
|
35
|
+
const target = fields.find(f => f.fieldId === titleFieldId);
|
|
36
|
+
if (!target) {
|
|
37
|
+
throw new _error.default(`Field selected for the title field does not exist in the model.`, "VALIDATION_ERROR", {
|
|
38
|
+
fieldId: titleFieldId,
|
|
39
|
+
fields
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (allowedTitleFieldTypes.includes(target.type) === false) {
|
|
43
|
+
throw new _error.default(`Only ${allowedTitleFieldTypes.join(", ")} and id fields can be used as an entry title.`, "ENTRY_TITLE_FIELD_TYPE", {
|
|
44
|
+
storageId: target.storageId,
|
|
45
|
+
fieldId: target.fieldId,
|
|
46
|
+
type: target.type
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (target.multipleValues) {
|
|
50
|
+
throw new _error.default(`Fields that accept multiple values cannot be used as the entry title.`, "ENTRY_TITLE_FIELD_TYPE", {
|
|
51
|
+
storageId: target.storageId,
|
|
52
|
+
fieldId: target.fieldId,
|
|
53
|
+
type: target.type
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return target.fieldId;
|
|
57
|
+
};
|
|
58
|
+
exports.getContentModelTitleFieldId = getContentModelTitleFieldId;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["defaultTitleFieldId","allowedTitleFieldTypes","getContentModelTitleFieldId","fields","titleFieldId","length","titleField","find","field","getBaseFieldType","multipleValues","fieldId","target","f","WebinyError","includes","type","join","storageId"],"sources":["titleField.ts"],"sourcesContent":["import { CmsModelField } from \"~/types\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\nimport WebinyError from \"@webiny/error\";\n\nconst defaultTitleFieldId = \"id\";\n\nconst allowedTitleFieldTypes = [\"text\", \"number\"];\n\nexport const getContentModelTitleFieldId = (\n fields: CmsModelField[],\n titleFieldId?: string\n): string => {\n /**\n * If there are no fields defined, we will return the default field\n */\n if (fields.length === 0) {\n return defaultTitleFieldId;\n }\n /**\n * if there is no title field defined either in input data or existing content model data\n * we will take first text field that has no multiple values enabled\n * or if initial titleFieldId is the default one also try to find first available text field\n */\n if (!titleFieldId || titleFieldId === defaultTitleFieldId) {\n const titleField = fields.find(field => {\n return getBaseFieldType(field) === \"text\" && !field.multipleValues;\n });\n return titleField?.fieldId || defaultTitleFieldId;\n }\n /**\n * check existing titleFieldId for existence in the model\n * for correct type\n * and that it is not multiple values field\n */\n const target = fields.find(f => f.fieldId === titleFieldId);\n if (!target) {\n throw new WebinyError(\n `Field selected for the title field does not exist in the model.`,\n \"VALIDATION_ERROR\",\n {\n fieldId: titleFieldId,\n fields\n }\n );\n }\n\n if (allowedTitleFieldTypes.includes(target.type) === false) {\n throw new WebinyError(\n `Only ${allowedTitleFieldTypes.join(\n \", \"\n )} and id fields can be used as an entry title.`,\n \"ENTRY_TITLE_FIELD_TYPE\",\n {\n storageId: target.storageId,\n fieldId: target.fieldId,\n type: target.type\n }\n );\n }\n\n if (target.multipleValues) {\n throw new WebinyError(\n `Fields that accept multiple values cannot be used as the entry title.`,\n \"ENTRY_TITLE_FIELD_TYPE\",\n {\n storageId: target.storageId,\n fieldId: target.fieldId,\n type: target.type\n }\n );\n }\n\n return target.fieldId;\n};\n"],"mappings":";;;;;;;AACA;AACA;AAEA,MAAMA,mBAAmB,GAAG,IAAI;AAEhC,MAAMC,sBAAsB,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC;AAE1C,MAAMC,2BAA2B,GAAG,CACvCC,MAAuB,EACvBC,YAAqB,KACZ;EACT;AACJ;AACA;EACI,IAAID,MAAM,CAACE,MAAM,KAAK,CAAC,EAAE;IACrB,OAAOL,mBAAmB;EAC9B;EACA;AACJ;AACA;AACA;AACA;EACI,IAAI,CAACI,YAAY,IAAIA,YAAY,KAAKJ,mBAAmB,EAAE;IACvD,MAAMM,UAAU,GAAGH,MAAM,CAACI,IAAI,CAACC,KAAK,IAAI;MACpC,OAAO,IAAAC,kCAAgB,EAACD,KAAK,CAAC,KAAK,MAAM,IAAI,CAACA,KAAK,CAACE,cAAc;IACtE,CAAC,CAAC;IACF,OAAO,CAAAJ,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEK,OAAO,KAAIX,mBAAmB;EACrD;EACA;AACJ;AACA;AACA;AACA;EACI,MAAMY,MAAM,GAAGT,MAAM,CAACI,IAAI,CAACM,CAAC,IAAIA,CAAC,CAACF,OAAO,KAAKP,YAAY,CAAC;EAC3D,IAAI,CAACQ,MAAM,EAAE;IACT,MAAM,IAAIE,cAAW,CAChB,iEAAgE,EACjE,kBAAkB,EAClB;MACIH,OAAO,EAAEP,YAAY;MACrBD;IACJ,CAAC,CACJ;EACL;EAEA,IAAIF,sBAAsB,CAACc,QAAQ,CAACH,MAAM,CAACI,IAAI,CAAC,KAAK,KAAK,EAAE;IACxD,MAAM,IAAIF,cAAW,CAChB,QAAOb,sBAAsB,CAACgB,IAAI,CAC/B,IAAI,CACN,+CAA8C,EAChD,wBAAwB,EACxB;MACIC,SAAS,EAAEN,MAAM,CAACM,SAAS;MAC3BP,OAAO,EAAEC,MAAM,CAACD,OAAO;MACvBK,IAAI,EAAEJ,MAAM,CAACI;IACjB,CAAC,CACJ;EACL;EAEA,IAAIJ,MAAM,CAACF,cAAc,EAAE;IACvB,MAAM,IAAII,cAAW,CAChB,uEAAsE,EACvE,wBAAwB,EACxB;MACII,SAAS,EAAEN,MAAM,CAACM,SAAS;MAC3BP,OAAO,EAAEC,MAAM,CAACD,OAAO;MACvBK,IAAI,EAAEJ,MAAM,CAACI;IACjB,CAAC,CACJ;EACL;EAEA,OAAOJ,MAAM,CAACD,OAAO;AACzB,CAAC;AAAC"}
|
|
@@ -4,33 +4,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.validateLayout = void 0;
|
|
7
|
-
|
|
8
7
|
const validateLayout = (layout, fields = []) => {
|
|
9
8
|
const flatLayoutIdList = layout.reduce((acc, id) => {
|
|
10
9
|
return acc.concat(Array.isArray(id) ? id : [id]);
|
|
11
10
|
}, []);
|
|
12
|
-
|
|
13
11
|
if (flatLayoutIdList.length !== fields.length) {
|
|
14
12
|
throw new Error(`There are ${flatLayoutIdList.length} IDs in the layout and ${fields.length} in fields, which cannot be - numbers must be the same.`);
|
|
15
13
|
}
|
|
16
|
-
|
|
17
14
|
for (const field of fields) {
|
|
18
15
|
if (flatLayoutIdList.includes(field.id)) {
|
|
19
16
|
continue;
|
|
20
17
|
}
|
|
21
|
-
|
|
22
18
|
throw new Error(`Field "${field.id}" is not defined in layout.`);
|
|
23
19
|
}
|
|
24
|
-
|
|
25
20
|
for (const id of flatLayoutIdList) {
|
|
26
21
|
const fieldFound = fields.some(f => f.id === id);
|
|
27
|
-
|
|
28
22
|
if (fieldFound) {
|
|
29
23
|
continue;
|
|
30
24
|
}
|
|
31
|
-
|
|
32
25
|
throw new Error(`Field id "${id}" is in layout but not in fields.`);
|
|
33
26
|
}
|
|
34
27
|
};
|
|
35
|
-
|
|
36
28
|
exports.validateLayout = validateLayout;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["validateLayout","layout","fields","flatLayoutIdList","reduce","acc","id","concat","Array","isArray","length","Error","field","includes","fieldFound","some","f"],"sources":["validateLayout.ts"],"sourcesContent":["import { CmsModelField, CmsModel } from \"~/types\";\n\nexport const validateLayout = (layout: CmsModel[\"layout\"], fields: CmsModelField[] = []): void => {\n const flatLayoutIdList = layout.reduce((acc, id) => {\n return acc.concat(Array.isArray(id) ? id : [id]);\n }, []);\n if (flatLayoutIdList.length !== fields.length) {\n throw new Error(\n `There are ${flatLayoutIdList.length} IDs in the layout and ${fields.length} in fields, which cannot be - numbers must be the same.`\n );\n }\n for (const field of fields) {\n if (flatLayoutIdList.includes(field.id)) {\n continue;\n }\n throw new Error(`Field \"${field.id}\" is not defined in layout.`);\n }\n for (const id of flatLayoutIdList) {\n const fieldFound = fields.some(f => f.id === id);\n if (fieldFound) {\n continue;\n }\n throw new Error(`Field id \"${id}\" is in layout but not in fields.`);\n }\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["validateLayout","layout","fields","flatLayoutIdList","reduce","acc","id","concat","Array","isArray","length","Error","field","includes","fieldFound","some","f"],"sources":["validateLayout.ts"],"sourcesContent":["import { CmsModelField, CmsModel } from \"~/types\";\n\nexport const validateLayout = (layout: CmsModel[\"layout\"], fields: CmsModelField[] = []): void => {\n const flatLayoutIdList = layout.reduce((acc, id) => {\n return acc.concat(Array.isArray(id) ? id : [id]);\n }, []);\n if (flatLayoutIdList.length !== fields.length) {\n throw new Error(\n `There are ${flatLayoutIdList.length} IDs in the layout and ${fields.length} in fields, which cannot be - numbers must be the same.`\n );\n }\n for (const field of fields) {\n if (flatLayoutIdList.includes(field.id)) {\n continue;\n }\n throw new Error(`Field \"${field.id}\" is not defined in layout.`);\n }\n for (const id of flatLayoutIdList) {\n const fieldFound = fields.some(f => f.id === id);\n if (fieldFound) {\n continue;\n }\n throw new Error(`Field id \"${id}\" is in layout but not in fields.`);\n }\n};\n"],"mappings":";;;;;;AAEO,MAAMA,cAAc,GAAG,CAACC,MAA0B,EAAEC,MAAuB,GAAG,EAAE,KAAW;EAC9F,MAAMC,gBAAgB,GAAGF,MAAM,CAACG,MAAM,CAAC,CAACC,GAAG,EAAEC,EAAE,KAAK;IAChD,OAAOD,GAAG,CAACE,MAAM,CAACC,KAAK,CAACC,OAAO,CAACH,EAAE,CAAC,GAAGA,EAAE,GAAG,CAACA,EAAE,CAAC,CAAC;EACpD,CAAC,EAAE,EAAE,CAAC;EACN,IAAIH,gBAAgB,CAACO,MAAM,KAAKR,MAAM,CAACQ,MAAM,EAAE;IAC3C,MAAM,IAAIC,KAAK,CACV,aAAYR,gBAAgB,CAACO,MAAO,0BAAyBR,MAAM,CAACQ,MAAO,yDAAwD,CACvI;EACL;EACA,KAAK,MAAME,KAAK,IAAIV,MAAM,EAAE;IACxB,IAAIC,gBAAgB,CAACU,QAAQ,CAACD,KAAK,CAACN,EAAE,CAAC,EAAE;MACrC;IACJ;IACA,MAAM,IAAIK,KAAK,CAAE,UAASC,KAAK,CAACN,EAAG,6BAA4B,CAAC;EACpE;EACA,KAAK,MAAMA,EAAE,IAAIH,gBAAgB,EAAE;IAC/B,MAAMW,UAAU,GAAGZ,MAAM,CAACa,IAAI,CAACC,CAAC,IAAIA,CAAC,CAACV,EAAE,KAAKA,EAAE,CAAC;IAChD,IAAIQ,UAAU,EAAE;MACZ;IACJ;IACA,MAAM,IAAIH,KAAK,CAAE,aAAYL,EAAG,mCAAkC,CAAC;EACvE;AACJ,CAAC;AAAC"}
|
|
@@ -1,18 +1,13 @@
|
|
|
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.validateModel = void 0;
|
|
9
|
-
|
|
10
8
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
-
|
|
12
9
|
var _CmsModelPlugin = require("../../plugins/CmsModelPlugin");
|
|
13
|
-
|
|
14
10
|
var _validateModelFields = require("./validateModelFields");
|
|
15
|
-
|
|
16
11
|
const validateModel = async params => {
|
|
17
12
|
const {
|
|
18
13
|
model,
|
|
@@ -22,14 +17,11 @@ const validateModel = async params => {
|
|
|
22
17
|
plugins
|
|
23
18
|
} = context;
|
|
24
19
|
const modelPlugin = plugins.byType(_CmsModelPlugin.CmsModelPlugin.type).find(item => item.contentModel.modelId === model.modelId);
|
|
25
|
-
|
|
26
20
|
if (modelPlugin) {
|
|
27
21
|
throw new _error.default("Content models defined via plugins cannot be updated.", "CONTENT_MODEL_UPDATE_ERROR", {
|
|
28
22
|
modelId: model.modelId
|
|
29
23
|
});
|
|
30
24
|
}
|
|
31
|
-
|
|
32
25
|
await (0, _validateModelFields.validateModelFields)(params);
|
|
33
26
|
};
|
|
34
|
-
|
|
35
27
|
exports.validateModel = validateModel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["validateModel","params","model","context","plugins","modelPlugin","byType","CmsModelPlugin","type","find","item","contentModel","modelId","WebinyError","validateModelFields"],"sources":["validateModel.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsModelPlugin } from \"~/plugins/CmsModelPlugin\";\nimport { CmsContext, CmsModel } from \"~/types\";\nimport { validateModelFields } from \"~/crud/contentModel/validateModelFields\";\n\ninterface ValidateModelParams {\n model: CmsModel;\n original?: CmsModel;\n context: CmsContext;\n}\n\nexport const validateModel = async (params: ValidateModelParams): Promise<void> => {\n const { model, context } = params;\n\n const { plugins } = context;\n\n const modelPlugin = plugins\n .byType<CmsModelPlugin>(CmsModelPlugin.type)\n .find(item => item.contentModel.modelId === model.modelId);\n\n if (modelPlugin) {\n throw new WebinyError(\n \"Content models defined via plugins cannot be updated.\",\n \"CONTENT_MODEL_UPDATE_ERROR\",\n {\n modelId: model.modelId\n }\n );\n }\n\n await validateModelFields(params);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["validateModel","params","model","context","plugins","modelPlugin","byType","CmsModelPlugin","type","find","item","contentModel","modelId","WebinyError","validateModelFields"],"sources":["validateModel.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsModelPlugin } from \"~/plugins/CmsModelPlugin\";\nimport { CmsContext, CmsModel } from \"~/types\";\nimport { validateModelFields } from \"~/crud/contentModel/validateModelFields\";\n\ninterface ValidateModelParams {\n models: CmsModel[];\n model: CmsModel;\n original?: CmsModel;\n context: CmsContext;\n}\n\nexport const validateModel = async (params: ValidateModelParams): Promise<void> => {\n const { model, context } = params;\n\n const { plugins } = context;\n\n const modelPlugin = plugins\n .byType<CmsModelPlugin>(CmsModelPlugin.type)\n .find(item => item.contentModel.modelId === model.modelId);\n\n if (modelPlugin) {\n throw new WebinyError(\n \"Content models defined via plugins cannot be updated.\",\n \"CONTENT_MODEL_UPDATE_ERROR\",\n {\n modelId: model.modelId\n }\n );\n }\n\n await validateModelFields(params);\n};\n"],"mappings":";;;;;;;AAAA;AACA;AAEA;AASO,MAAMA,aAAa,GAAG,MAAOC,MAA2B,IAAoB;EAC/E,MAAM;IAAEC,KAAK;IAAEC;EAAQ,CAAC,GAAGF,MAAM;EAEjC,MAAM;IAAEG;EAAQ,CAAC,GAAGD,OAAO;EAE3B,MAAME,WAAW,GAAGD,OAAO,CACtBE,MAAM,CAAiBC,8BAAc,CAACC,IAAI,CAAC,CAC3CC,IAAI,CAACC,IAAI,IAAIA,IAAI,CAACC,YAAY,CAACC,OAAO,KAAKV,KAAK,CAACU,OAAO,CAAC;EAE9D,IAAIP,WAAW,EAAE;IACb,MAAM,IAAIQ,cAAW,CACjB,uDAAuD,EACvD,4BAA4B,EAC5B;MACID,OAAO,EAAEV,KAAK,CAACU;IACnB,CAAC,CACJ;EACL;EAEA,MAAM,IAAAE,wCAAmB,EAACb,MAAM,CAAC;AACrC,CAAC;AAAC"}
|
|
@@ -1,98 +1,31 @@
|
|
|
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.validateModelFields = void 0;
|
|
9
|
-
|
|
10
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
9
|
+
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
|
12
10
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
-
|
|
14
11
|
var _createManageSDL = require("../../graphql/schema/createManageSDL");
|
|
15
|
-
|
|
16
|
-
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
|
17
|
-
|
|
18
12
|
var _createFieldStorageId = require("./createFieldStorageId");
|
|
19
|
-
|
|
20
13
|
var _getBaseFieldType = require("../../utils/getBaseFieldType");
|
|
21
|
-
|
|
14
|
+
var _titleField = require("./fields/titleField");
|
|
15
|
+
var _descriptionField = require("./fields/descriptionField");
|
|
16
|
+
var _imageField = require("./fields/imageField");
|
|
22
17
|
var _plugins = require("../../plugins");
|
|
23
|
-
|
|
24
18
|
var _buildSchemaPlugins = require("../../graphql/buildSchemaPlugins");
|
|
25
|
-
|
|
26
19
|
var _createExecutableSchema = require("../../graphql/createExecutableSchema");
|
|
27
|
-
|
|
28
20
|
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
29
|
-
|
|
30
|
-
const defaultTitleFieldId = "id";
|
|
31
|
-
const allowedTitleFieldTypes = ["text", "number"];
|
|
32
|
-
|
|
33
|
-
const getContentModelTitleFieldId = (fields, titleFieldId) => {
|
|
34
|
-
/**
|
|
35
|
-
* If there are no fields defined, we will return the default field
|
|
36
|
-
*/
|
|
37
|
-
if (fields.length === 0) {
|
|
38
|
-
return defaultTitleFieldId;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* if there is no title field defined either in input data or existing content model data
|
|
42
|
-
* we will take first text field that has no multiple values enabled
|
|
43
|
-
* or if initial titleFieldId is the default one also try to find first available text field
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (!titleFieldId || titleFieldId === defaultTitleFieldId) {
|
|
48
|
-
const titleField = fields.find(field => {
|
|
49
|
-
return (0, _getBaseFieldType.getBaseFieldType)(field) === "text" && !field.multipleValues;
|
|
50
|
-
});
|
|
51
|
-
return (titleField === null || titleField === void 0 ? void 0 : titleField.fieldId) || defaultTitleFieldId;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* check existing titleFieldId for existence in the model
|
|
55
|
-
* for correct type
|
|
56
|
-
* and that it is not multiple values field
|
|
57
|
-
*/
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const target = fields.find(f => f.fieldId === titleFieldId);
|
|
61
|
-
|
|
62
|
-
if (!target) {
|
|
63
|
-
throw new _error.default(`Field selected for the title field does not exist in the model.`, "VALIDATION_ERROR", {
|
|
64
|
-
fieldId: titleFieldId,
|
|
65
|
-
fields
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (allowedTitleFieldTypes.includes(target.type) === false) {
|
|
70
|
-
throw new _error.default(`Only ${allowedTitleFieldTypes.join(", ")} and id fields can be used as an entry title.`, "ENTRY_TITLE_FIELD_TYPE", {
|
|
71
|
-
storageId: target.storageId,
|
|
72
|
-
fieldId: target.fieldId,
|
|
73
|
-
type: target.type
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (target.multipleValues) {
|
|
78
|
-
throw new _error.default(`Fields that accept multiple values cannot be used as the entry title.`, "ENTRY_TITLE_FIELD_TYPE", {
|
|
79
|
-
storageId: target.storageId,
|
|
80
|
-
fieldId: target.fieldId,
|
|
81
|
-
type: target.type
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return target.fieldId;
|
|
86
|
-
};
|
|
87
|
-
|
|
21
|
+
var _utils = require("@webiny/utils");
|
|
88
22
|
const extractInvalidField = (model, err) => {
|
|
89
23
|
var _err$source;
|
|
90
|
-
|
|
91
24
|
const sdl = ((_err$source = err.source) === null || _err$source === void 0 ? void 0 : _err$source.body) || "";
|
|
25
|
+
|
|
92
26
|
/**
|
|
93
27
|
* Find the invalid type
|
|
94
28
|
*/
|
|
95
|
-
|
|
96
29
|
const {
|
|
97
30
|
line: lineNumber
|
|
98
31
|
} = err.locations ? err.locations[0] : {
|
|
@@ -101,33 +34,25 @@ const extractInvalidField = (model, err) => {
|
|
|
101
34
|
const sdlLines = sdl.split("\n");
|
|
102
35
|
let sdlLine;
|
|
103
36
|
let gqlType;
|
|
104
|
-
|
|
105
37
|
for (let i = lineNumber; i > 0; i--) {
|
|
106
38
|
if (sdlLine && sdlLine.includes("type ")) {
|
|
107
39
|
gqlType = sdlLine.match(/type\s+(.*?)\s+{/);
|
|
108
40
|
break;
|
|
109
41
|
}
|
|
110
|
-
|
|
111
42
|
sdlLine = sdlLines[i];
|
|
112
43
|
}
|
|
113
|
-
|
|
114
44
|
let invalidField = undefined;
|
|
115
|
-
|
|
116
45
|
if (Array.isArray(gqlType)) {
|
|
117
46
|
const fieldRegex = new RegExp(`([^\\s+].*?):\\s+\\[?${gqlType[1]}!?\\]?`);
|
|
118
47
|
const matched = sdl.match(fieldRegex);
|
|
119
|
-
|
|
120
48
|
if (matched) {
|
|
121
49
|
invalidField = matched[1];
|
|
122
50
|
}
|
|
123
51
|
}
|
|
124
|
-
|
|
125
52
|
let message = `See more details in the browser console.`;
|
|
126
|
-
|
|
127
53
|
if (invalidField) {
|
|
128
54
|
message = `Please review the definition of "${invalidField}" field.`;
|
|
129
55
|
}
|
|
130
|
-
|
|
131
56
|
return {
|
|
132
57
|
data: {
|
|
133
58
|
modelId: model.modelId,
|
|
@@ -138,7 +63,6 @@ const extractInvalidField = (model, err) => {
|
|
|
138
63
|
message: [`Model "${model.modelId}" was not saved!`, message].join("\n")
|
|
139
64
|
};
|
|
140
65
|
};
|
|
141
|
-
|
|
142
66
|
const createValidateChildFields = plugins => {
|
|
143
67
|
return ({
|
|
144
68
|
fields,
|
|
@@ -147,7 +71,6 @@ const createValidateChildFields = plugins => {
|
|
|
147
71
|
if (fields.length === 0 && originalFields.length === 0) {
|
|
148
72
|
return;
|
|
149
73
|
}
|
|
150
|
-
|
|
151
74
|
validateFields({
|
|
152
75
|
fields,
|
|
153
76
|
originalFields,
|
|
@@ -156,7 +79,6 @@ const createValidateChildFields = plugins => {
|
|
|
156
79
|
});
|
|
157
80
|
};
|
|
158
81
|
};
|
|
159
|
-
|
|
160
82
|
const validateFields = params => {
|
|
161
83
|
const {
|
|
162
84
|
plugins,
|
|
@@ -167,11 +89,9 @@ const validateFields = params => {
|
|
|
167
89
|
const idList = [];
|
|
168
90
|
const fieldIdList = [];
|
|
169
91
|
const storageIdList = [];
|
|
170
|
-
|
|
171
92
|
for (const field of fields) {
|
|
172
93
|
const baseType = (0, _getBaseFieldType.getBaseFieldType)(field);
|
|
173
94
|
const plugin = plugins.find(plugin => plugin.fieldType === baseType);
|
|
174
|
-
|
|
175
95
|
if (!plugin) {
|
|
176
96
|
throw new Error(`Cannot update content model because of the unknown "${baseType}" field.`);
|
|
177
97
|
}
|
|
@@ -179,18 +99,14 @@ const validateFields = params => {
|
|
|
179
99
|
* Check the field's id against existing ones.
|
|
180
100
|
* There cannot be two fields with the same id.
|
|
181
101
|
*/
|
|
182
|
-
|
|
183
|
-
|
|
184
102
|
if (idList.includes(field.id)) {
|
|
185
103
|
throw new _error.default(`Cannot update content model because field "${field.storageId || field.fieldId}" has id "${field.id}", which is already used.`);
|
|
186
104
|
}
|
|
187
|
-
|
|
188
105
|
idList.push(field.id);
|
|
189
106
|
const originalField = originalFields.find(f => f.id === field.id);
|
|
190
107
|
/**
|
|
191
108
|
* Field MUST have an fieldId defined.
|
|
192
109
|
*/
|
|
193
|
-
|
|
194
110
|
if (!field.fieldId) {
|
|
195
111
|
throw new _error.default(`Field does not have an "fieldId" defined.`, "MISSING_FIELD_ID", {
|
|
196
112
|
field
|
|
@@ -209,12 +125,9 @@ const validateFields = params => {
|
|
|
209
125
|
* https://discuss.elastic.co/t/special-characters-in-field-names/10658/3
|
|
210
126
|
* https://discuss.elastic.co/t/illegal-characters-in-elasticsearch-field-names/17196/2
|
|
211
127
|
*/
|
|
212
|
-
|
|
213
|
-
|
|
214
128
|
const isLocked = lockedFields.some(lockedField => {
|
|
215
129
|
return lockedField.fieldId === field.storageId || lockedField.fieldId === field.fieldId;
|
|
216
130
|
});
|
|
217
|
-
|
|
218
131
|
if (!field.storageId) {
|
|
219
132
|
/**
|
|
220
133
|
* In case field is locked, we must set the storageId to the fieldId value.
|
|
@@ -243,32 +156,25 @@ const validateFields = params => {
|
|
|
243
156
|
* Check the field's fieldId against existing ones.
|
|
244
157
|
* There cannot be two fields with the same fieldId - outside world identifier.
|
|
245
158
|
*/
|
|
246
|
-
|
|
247
|
-
|
|
248
159
|
if (fieldIdList.includes(field.fieldId)) {
|
|
249
160
|
throw new _error.default(`Cannot update content model because field "${field.storageId}" has fieldId "${field.fieldId}", which is already used.`);
|
|
250
161
|
}
|
|
251
|
-
|
|
252
162
|
fieldIdList.push(field.fieldId);
|
|
253
163
|
/**
|
|
254
164
|
* Check the field's storageId against the existing ones.
|
|
255
165
|
* There cannot be two fields with the same storageId.
|
|
256
166
|
*/
|
|
257
|
-
|
|
258
167
|
if (storageIdList.includes(field.storageId)) {
|
|
259
168
|
throw new _error.default(`Cannot update content model because field "${field.label}" has storageId "${field.storageId}", which is already used.`);
|
|
260
169
|
}
|
|
261
|
-
|
|
262
170
|
storageIdList.push(field.storageId);
|
|
263
171
|
/**
|
|
264
172
|
* There might be some plugins which allow child fields.
|
|
265
173
|
* We use this method to validate them as well.
|
|
266
174
|
*/
|
|
267
|
-
|
|
268
175
|
if (!plugin.validateChildFields) {
|
|
269
176
|
continue;
|
|
270
177
|
}
|
|
271
|
-
|
|
272
178
|
const validateChildFields = createValidateChildFields(plugins);
|
|
273
179
|
plugin.validateChildFields({
|
|
274
180
|
field,
|
|
@@ -277,59 +183,70 @@ const validateFields = params => {
|
|
|
277
183
|
});
|
|
278
184
|
}
|
|
279
185
|
};
|
|
280
|
-
|
|
281
186
|
const createGraphQLSchema = async params => {
|
|
282
187
|
const {
|
|
283
188
|
context,
|
|
284
189
|
model
|
|
285
190
|
} = params;
|
|
191
|
+
context.security.disableAuthorization();
|
|
192
|
+
const models = (await context.cms.listModels()).filter(model => {
|
|
193
|
+
return !model.isPrivate;
|
|
194
|
+
});
|
|
195
|
+
context.security.enableAuthorization();
|
|
286
196
|
const modelPlugins = await (0, _buildSchemaPlugins.buildSchemaPlugins)({
|
|
287
197
|
context,
|
|
288
|
-
models: [model]
|
|
198
|
+
models: models.concat([model])
|
|
289
199
|
});
|
|
290
|
-
const plugins = context.plugins.byType(_handlerGraphql.GraphQLSchemaPlugin.type)
|
|
291
|
-
|
|
200
|
+
const plugins = context.plugins.byType(_handlerGraphql.GraphQLSchemaPlugin.type).reduce((collection, plugin) => {
|
|
201
|
+
const name = plugin.name || `${plugin.type}-${(0, _utils.generateAlphaNumericId)(16)}`;
|
|
202
|
+
collection[name] = plugin;
|
|
203
|
+
return collection;
|
|
204
|
+
}, {});
|
|
205
|
+
for (const plugin of modelPlugins) {
|
|
206
|
+
const name = plugin.name || `${plugin.type}-${(0, _utils.generateAlphaNumericId)(16)}`;
|
|
207
|
+
plugins[name] = plugin;
|
|
208
|
+
}
|
|
292
209
|
return (0, _createExecutableSchema.createExecutableSchema)({
|
|
293
|
-
plugins
|
|
210
|
+
plugins: Object.values(plugins)
|
|
294
211
|
});
|
|
295
212
|
};
|
|
296
|
-
|
|
297
213
|
const extractErrorObject = error => {
|
|
298
214
|
return ["message", "code", "data", "stack"].reduce((output, key) => {
|
|
299
215
|
if (!error[key]) {
|
|
300
216
|
return output;
|
|
301
217
|
}
|
|
302
|
-
|
|
303
218
|
output[key] = error[key];
|
|
304
219
|
return output;
|
|
305
220
|
}, {});
|
|
306
221
|
};
|
|
307
|
-
|
|
308
222
|
const validateModelFields = async params => {
|
|
309
223
|
const {
|
|
224
|
+
models,
|
|
310
225
|
model,
|
|
311
226
|
original,
|
|
312
227
|
context
|
|
313
228
|
} = params;
|
|
314
229
|
const {
|
|
315
|
-
titleFieldId
|
|
230
|
+
titleFieldId,
|
|
231
|
+
descriptionFieldId,
|
|
232
|
+
imageFieldId
|
|
316
233
|
} = model;
|
|
317
234
|
const {
|
|
318
235
|
plugins
|
|
319
236
|
} = context;
|
|
237
|
+
|
|
320
238
|
/**
|
|
321
239
|
* There should be fields/locked fields in either model or data to be updated.
|
|
322
240
|
*/
|
|
323
|
-
|
|
324
241
|
const {
|
|
325
242
|
fields = [],
|
|
326
243
|
lockedFields = []
|
|
327
244
|
} = model;
|
|
245
|
+
|
|
328
246
|
/**
|
|
329
247
|
* Let's inspect the fields of the received content model. We prevent saving of a content model if it
|
|
330
248
|
* contains a field for which a "cms-model-field-to-graphql" plugin does not exist on the backend.
|
|
331
249
|
*/
|
|
332
|
-
|
|
333
250
|
const fieldTypePlugins = plugins.byType("cms-model-field-to-graphql");
|
|
334
251
|
validateFields({
|
|
335
252
|
fields,
|
|
@@ -337,21 +254,19 @@ const validateModelFields = async params => {
|
|
|
337
254
|
lockedFields,
|
|
338
255
|
plugins: fieldTypePlugins
|
|
339
256
|
});
|
|
340
|
-
|
|
341
257
|
if (fields.length) {
|
|
342
258
|
const sorterPlugins = plugins.byType(_plugins.CmsGraphQLSchemaSorterPlugin.type);
|
|
343
259
|
/**
|
|
344
260
|
* Make sure that this model can be safely converted to a GraphQL SDL
|
|
345
261
|
*/
|
|
346
|
-
|
|
347
262
|
const schema = (0, _createManageSDL.createManageSDL)({
|
|
263
|
+
models,
|
|
348
264
|
model,
|
|
349
265
|
fieldTypePlugins: fieldTypePlugins.reduce((acc, pl) => (0, _objectSpread2.default)((0, _objectSpread2.default)({}, acc), {}, {
|
|
350
266
|
[pl.fieldType]: pl
|
|
351
267
|
}), {}),
|
|
352
268
|
sorterPlugins
|
|
353
269
|
});
|
|
354
|
-
|
|
355
270
|
try {
|
|
356
271
|
(0, _graphqlTag.default)(schema);
|
|
357
272
|
} catch (err) {
|
|
@@ -360,8 +275,6 @@ const validateModelFields = async params => {
|
|
|
360
275
|
/**
|
|
361
276
|
*
|
|
362
277
|
*/
|
|
363
|
-
|
|
364
|
-
|
|
365
278
|
try {
|
|
366
279
|
await createGraphQLSchema({
|
|
367
280
|
context,
|
|
@@ -378,34 +291,32 @@ const validateModelFields = async params => {
|
|
|
378
291
|
});
|
|
379
292
|
}
|
|
380
293
|
}
|
|
381
|
-
|
|
382
|
-
model.
|
|
294
|
+
model.titleFieldId = (0, _titleField.getContentModelTitleFieldId)(fields, titleFieldId);
|
|
295
|
+
model.descriptionFieldId = (0, _descriptionField.getContentModelDescriptionFieldId)(fields, descriptionFieldId);
|
|
296
|
+
model.imageFieldId = (0, _imageField.getContentModelImageFieldId)(fields, imageFieldId);
|
|
383
297
|
const cmsLockedFieldPlugins = plugins.byType("cms-model-locked-field");
|
|
298
|
+
|
|
384
299
|
/**
|
|
385
300
|
* We must not allow removal or changes in fields that are already in use in content entries.
|
|
386
301
|
* Locked fields still have fieldId (should be storageId) because of the old existing locked fields in the models.
|
|
387
302
|
*/
|
|
388
|
-
|
|
389
303
|
for (const lockedField of lockedFields) {
|
|
390
304
|
const existingField = fields.find(item => item.storageId === lockedField.fieldId);
|
|
305
|
+
|
|
391
306
|
/**
|
|
392
307
|
* Starting with 5.33.0 fields can be deleted.
|
|
393
308
|
* Our UI gives a warning upon locked field deletion, but if user is managing fields through API directly - we cannot do anything.
|
|
394
309
|
*/
|
|
395
|
-
|
|
396
310
|
if (!existingField) {
|
|
397
311
|
continue;
|
|
398
312
|
}
|
|
399
|
-
|
|
400
313
|
if (lockedField.multipleValues !== existingField.multipleValues) {
|
|
401
314
|
throw new _error.default(`Cannot change "multipleValues" for the "${lockedField.fieldId}" field because it's already in use in created content.`, "ENTRY_FIELD_USED", {
|
|
402
315
|
reason: `"multipleValues" changed`,
|
|
403
316
|
field: existingField
|
|
404
317
|
});
|
|
405
318
|
}
|
|
406
|
-
|
|
407
319
|
const fieldType = (0, _getBaseFieldType.getBaseFieldType)(existingField);
|
|
408
|
-
|
|
409
320
|
if (lockedField.type !== fieldType) {
|
|
410
321
|
throw new _error.default(`Cannot change field type for the "${lockedField.fieldId}" field because it's already in use in created content.`, "ENTRY_FIELD_USED", {
|
|
411
322
|
reason: `"type" changed`,
|
|
@@ -413,18 +324,15 @@ const validateModelFields = async params => {
|
|
|
413
324
|
existingFieldType: fieldType
|
|
414
325
|
});
|
|
415
326
|
}
|
|
327
|
+
|
|
416
328
|
/**
|
|
417
329
|
* Check `lockedField` invariant for specific field
|
|
418
330
|
*/
|
|
419
|
-
|
|
420
|
-
|
|
421
331
|
const lockedFieldsByType = cmsLockedFieldPlugins.filter(pl => pl.fieldType === (0, _getBaseFieldType.getBaseFieldType)(lockedField));
|
|
422
|
-
|
|
423
332
|
for (const plugin of lockedFieldsByType) {
|
|
424
333
|
if (typeof plugin.checkLockedField !== "function") {
|
|
425
334
|
continue;
|
|
426
335
|
}
|
|
427
|
-
|
|
428
336
|
plugin.checkLockedField({
|
|
429
337
|
lockedField,
|
|
430
338
|
field: existingField
|
|
@@ -432,5 +340,4 @@ const validateModelFields = async params => {
|
|
|
432
340
|
}
|
|
433
341
|
}
|
|
434
342
|
};
|
|
435
|
-
|
|
436
343
|
exports.validateModelFields = validateModelFields;
|