@webiny/api-headless-cms 0.0.0-unstable.990c3ab1b6 → 0.0.0-unstable.99666aeb00
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/constants.d.ts +1 -0
- package/constants.js +8 -0
- package/constants.js.map +1 -0
- package/context.d.ts +5 -2
- package/context.js +94 -9
- package/context.js.map +1 -1
- package/crud/contentEntry/markLockedFields.d.ts +1 -1
- package/crud/contentEntry/markLockedFields.js +17 -4
- package/crud/contentEntry/markLockedFields.js.map +1 -1
- package/crud/contentEntry/referenceFieldsMapping.js +40 -9
- 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 +12 -5
- package/crud/contentEntry.crud.js +1195 -855
- package/crud/contentEntry.crud.js.map +1 -1
- package/crud/contentModel/beforeCreate.d.ts +2 -3
- package/crud/contentModel/beforeCreate.js +43 -81
- package/crud/contentModel/beforeCreate.js.map +1 -1
- package/crud/contentModel/beforeDelete.d.ts +1 -1
- package/crud/contentModel/beforeDelete.js +1 -5
- package/crud/contentModel/beforeDelete.js.map +1 -1
- package/crud/contentModel/beforeUpdate.d.ts +2 -4
- package/crud/contentModel/beforeUpdate.js +33 -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/createFieldStorageId.js +4 -1
- 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/validate/endingAllowed.d.ts +6 -0
- package/crud/contentModel/validate/endingAllowed.js +26 -0
- package/crud/contentModel/validate/endingAllowed.js.map +1 -0
- package/crud/contentModel/validate/isModelEndingAllowed.d.ts +6 -0
- package/crud/contentModel/validate/isModelEndingAllowed.js +24 -0
- package/crud/contentModel/validate/isModelEndingAllowed.js.map +1 -0
- package/crud/contentModel/validate/modelId.d.ts +11 -0
- package/crud/contentModel/validate/modelId.js +36 -0
- package/crud/contentModel/validate/modelId.js.map +1 -0
- package/crud/contentModel/validate/pluralApiName.d.ts +7 -0
- package/crud/contentModel/validate/pluralApiName.js +24 -0
- package/crud/contentModel/validate/pluralApiName.js.map +1 -0
- package/crud/contentModel/validate/singularApiName.d.ts +7 -0
- package/crud/contentModel/validate/singularApiName.js +24 -0
- package/crud/contentModel/validate/singularApiName.js.map +1 -0
- package/crud/contentModel/validateModel.d.ts +4 -4
- package/crud/contentModel/validateModel.js +6 -3
- package/crud/contentModel/validateModel.js.map +1 -1
- package/crud/contentModel/validateModelFields.d.ts +4 -4
- package/crud/contentModel/validateModelFields.js +124 -89
- package/crud/contentModel/validateModelFields.js.map +1 -1
- package/crud/contentModel/validation.d.ts +551 -0
- package/crud/contentModel/validation.js +145 -0
- package/crud/contentModel/validation.js.map +1 -0
- package/crud/contentModel.crud.d.ts +2 -0
- package/crud/contentModel.crud.js +385 -279
- package/crud/contentModel.crud.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.d.ts +2 -0
- package/crud/contentModelGroup.crud.js +218 -180
- package/crud/contentModelGroup.crud.js.map +1 -1
- package/crud/settings.crud.d.ts +3 -1
- package/crud/settings.crud.js +7 -16
- package/crud/settings.crud.js.map +1 -1
- package/crud/system.crud.js +0 -60
- package/crud/system.crud.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/index.d.ts +2 -1
- package/fieldConverters/index.js +2 -1
- package/fieldConverters/index.js.map +1 -1
- package/graphql/buildSchemaPlugins.d.ts +8 -3
- package/graphql/buildSchemaPlugins.js +3 -7
- package/graphql/buildSchemaPlugins.js.map +1 -1
- package/graphql/checkEndpointAccess.d.ts +2 -0
- package/graphql/checkEndpointAccess.js +18 -0
- package/graphql/checkEndpointAccess.js.map +1 -0
- package/graphql/createExecutableSchema.d.ts +6 -0
- package/graphql/createExecutableSchema.js +29 -0
- package/graphql/createExecutableSchema.js.map +1 -0
- package/graphql/createRequestBody.d.ts +2 -0
- package/graphql/createRequestBody.js +14 -0
- package/graphql/createRequestBody.js.map +1 -0
- package/graphql/formatErrorPayload.d.ts +1 -0
- package/graphql/formatErrorPayload.js +25 -0
- package/graphql/formatErrorPayload.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/getSchema.d.ts +17 -0
- package/graphql/getSchema.js +102 -0
- package/graphql/getSchema.js.map +1 -0
- package/graphql/graphQLHandlerFactory.js +6 -104
- package/graphql/graphQLHandlerFactory.js.map +1 -1
- package/graphql/handleRequest.d.ts +11 -0
- package/graphql/handleRequest.js +81 -0
- package/graphql/handleRequest.js.map +1 -0
- package/graphql/index.d.ts +1 -3
- package/graphql/index.js +2 -39
- package/graphql/index.js.map +1 -1
- package/graphql/schema/baseContentSchema.d.ts +6 -2
- package/graphql/schema/baseContentSchema.js +9 -11
- package/graphql/schema/baseContentSchema.js.map +1 -1
- package/graphql/schema/baseSchema.d.ts +3 -0
- package/graphql/schema/baseSchema.js +84 -0
- package/graphql/schema/baseSchema.js.map +1 -0
- package/graphql/schema/contentEntries.d.ts +6 -2
- package/graphql/schema/contentEntries.js +121 -65
- package/graphql/schema/contentEntries.js.map +1 -1
- package/graphql/schema/contentModelGroups.d.ts +6 -2
- package/graphql/schema/contentModelGroups.js +14 -10
- package/graphql/schema/contentModelGroups.js.map +1 -1
- package/graphql/schema/contentModels.d.ts +6 -2
- package/graphql/schema/contentModels.js +60 -8
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createFieldResolvers.d.ts +2 -2
- package/graphql/schema/createFieldResolvers.js +18 -13
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/graphql/schema/createFieldTypePluginRecords.d.ts +3 -0
- package/graphql/schema/createFieldTypePluginRecords.js +13 -0
- package/graphql/schema/createFieldTypePluginRecords.js.map +1 -0
- package/graphql/schema/createManageResolvers.d.ts +1 -1
- package/graphql/schema/createManageResolvers.js +47 -17
- package/graphql/schema/createManageResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.d.ts +3 -0
- package/graphql/schema/createManageSDL.js +96 -63
- package/graphql/schema/createManageSDL.js.map +1 -1
- package/graphql/schema/createPreviewResolvers.js +3 -7
- package/graphql/schema/createPreviewResolvers.js.map +1 -1
- package/graphql/schema/createReadResolvers.js +8 -7
- package/graphql/schema/createReadResolvers.js.map +1 -1
- package/graphql/schema/createReadSDL.d.ts +3 -0
- package/graphql/schema/createReadSDL.js +48 -36
- package/graphql/schema/createReadSDL.js.map +1 -1
- package/graphql/schema/resolvers/commonFieldResolvers.d.ts +3 -2
- package/graphql/schema/resolvers/commonFieldResolvers.js +2 -1
- package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveDelete.d.ts +2 -1
- package/graphql/schema/resolvers/manage/resolveDelete.js +13 -3
- package/graphql/schema/resolvers/manage/resolveDelete.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveDeleteMultiple.d.ts +7 -0
- package/graphql/schema/resolvers/manage/resolveDeleteMultiple.js +20 -0
- package/graphql/schema/resolvers/manage/resolveDeleteMultiple.js.map +1 -0
- package/graphql/schema/resolvers/manage/resolveGetUniqueFieldValues.d.ts +4 -0
- package/graphql/schema/resolvers/manage/resolveGetUniqueFieldValues.js +18 -0
- package/graphql/schema/resolvers/manage/resolveGetUniqueFieldValues.js.map +1 -0
- package/graphql/schema/resolvers/manage/resolveMove.d.ts +8 -0
- package/graphql/schema/resolvers/manage/resolveMove.js +30 -0
- package/graphql/schema/resolvers/manage/resolveMove.js.map +1 -0
- package/graphql/schema/schemaPlugins.d.ts +8 -3
- package/graphql/schema/schemaPlugins.js +55 -52
- package/graphql/schema/schemaPlugins.js.map +1 -1
- package/graphql/system.d.ts +2 -5
- package/graphql/system.js +56 -85
- package/graphql/system.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +2 -0
- package/graphqlFields/dynamicZone/dynamicZoneField.js +243 -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/index.d.ts +1 -1
- package/graphqlFields/index.js +2 -1
- package/graphqlFields/index.js.map +1 -1
- package/graphqlFields/number.js +5 -0
- package/graphqlFields/number.js.map +1 -1
- package/graphqlFields/object.js +131 -68
- package/graphqlFields/object.js.map +1 -1
- package/graphqlFields/ref.js +70 -56
- package/graphqlFields/ref.js.map +1 -1
- package/graphqlFields/text.js +2 -0
- package/graphqlFields/text.js.map +1 -1
- package/index.d.ts +5 -3
- package/index.js +27 -8
- package/index.js.map +1 -1
- package/package.json +36 -41
- 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/CmsModelFieldConverterPlugin.d.ts +2 -2
- package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
- package/plugins/CmsModelPlugin.d.ts +21 -3
- package/plugins/CmsModelPlugin.js +28 -2
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/plugins/StorageOperationsCmsModelPlugin.d.ts +23 -0
- package/plugins/StorageOperationsCmsModelPlugin.js +42 -0
- package/plugins/StorageOperationsCmsModelPlugin.js.map +1 -0
- package/plugins/StorageTransformPlugin.d.ts +11 -11
- package/plugins/StorageTransformPlugin.js.map +1 -1
- package/plugins/index.d.ts +3 -0
- package/plugins/index.js +33 -0
- package/plugins/index.js.map +1 -1
- package/storage/object.js +4 -2
- package/storage/object.js.map +1 -1
- package/types.d.ts +455 -135
- package/types.js +74 -8
- package/types.js.map +1 -1
- package/utils/converters/ConverterCollection.js +5 -2
- package/utils/converters/ConverterCollection.js.map +1 -1
- package/utils/converters/valueKeyStorageConverter.d.ts +1 -5
- package/utils/converters/valueKeyStorageConverter.js +26 -20
- package/utils/converters/valueKeyStorageConverter.js.map +1 -1
- package/utils/createTypeFromFields.d.ts +16 -0
- package/utils/createTypeFromFields.js +66 -0
- package/utils/createTypeFromFields.js.map +1 -0
- package/utils/createTypeName.d.ts +0 -2
- package/utils/createTypeName.js +4 -11
- package/utils/createTypeName.js.map +1 -1
- package/utils/entryStorage.js +14 -11
- package/utils/entryStorage.js.map +1 -1
- package/utils/getBaseFieldType.d.ts +2 -0
- package/utils/getBaseFieldType.js +10 -0
- package/utils/getBaseFieldType.js.map +1 -0
- 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.d.ts +1 -1
- package/utils/getEntryTitle.js.map +1 -1
- package/utils/getSchemaFromFieldPlugins.d.ts +4 -7
- package/utils/getSchemaFromFieldPlugins.js +22 -14
- package/utils/getSchemaFromFieldPlugins.js.map +1 -1
- package/utils/incrementEntryIdVersion.d.ts +5 -0
- package/utils/incrementEntryIdVersion.js +29 -0
- package/utils/incrementEntryIdVersion.js.map +1 -0
- package/utils/permissions/EntriesPermissions.d.ts +4 -0
- package/utils/permissions/EntriesPermissions.js +9 -0
- package/utils/permissions/EntriesPermissions.js.map +1 -0
- package/utils/permissions/ModelGroupsPermissions.d.ts +11 -0
- package/utils/permissions/ModelGroupsPermissions.js +48 -0
- package/utils/permissions/ModelGroupsPermissions.js.map +1 -0
- package/utils/permissions/ModelsPermissions.d.ts +20 -0
- package/utils/permissions/ModelsPermissions.js +91 -0
- package/utils/permissions/ModelsPermissions.js.map +1 -0
- package/utils/permissions/SettingsPermissions.d.ts +4 -0
- package/utils/permissions/SettingsPermissions.js +9 -0
- package/utils/permissions/SettingsPermissions.js.map +1 -0
- package/utils/renderFields.d.ts +4 -2
- package/utils/renderFields.js +12 -3
- package/utils/renderFields.js.map +1 -1
- package/utils/renderGetFilterFields.d.ts +2 -2
- package/utils/renderGetFilterFields.js +9 -19
- package/utils/renderGetFilterFields.js.map +1 -1
- package/utils/renderInputFields.d.ts +4 -2
- package/utils/renderInputFields.js +19 -6
- package/utils/renderInputFields.js.map +1 -1
- package/utils/renderListFilterFields.d.ts +3 -1
- package/utils/renderListFilterFields.js +19 -22
- package/utils/renderListFilterFields.js.map +1 -1
- package/utils/renderSortEnum.d.ts +9 -5
- package/utils/renderSortEnum.js +26 -5
- package/utils/renderSortEnum.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/index.js +2 -1
- package/validators/index.js.map +1 -1
- package/crud/contentModel/createFieldModels.d.ts +0 -2
- package/crud/contentModel/createFieldModels.js +0 -20
- package/crud/contentModel/createFieldModels.js.map +0 -1
- package/crud/contentModel/fieldIdValidation.d.ts +0 -1
- package/crud/contentModel/fieldIdValidation.js +0 -20
- package/crud/contentModel/fieldIdValidation.js.map +0 -1
- package/crud/contentModel/idValidation.d.ts +0 -1
- package/crud/contentModel/idValidation.js +0 -17
- package/crud/contentModel/idValidation.js.map +0 -1
- package/crud/contentModel/models.d.ts +0 -4
- package/crud/contentModel/models.js +0 -173
- package/crud/contentModel/models.js.map +0 -1
- package/crud/contentModel/systemFields.d.ts +0 -1
- package/crud/contentModel/systemFields.js +0 -8
- package/crud/contentModel/systemFields.js.map +0 -1
- package/crud/index.d.ts +0 -6
- package/crud/index.js +0 -69
- 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/upgrades/5.33.0/index.d.ts +0 -3
- package/upgrades/5.33.0/index.js +0 -159
- package/upgrades/5.33.0/index.js.map +0 -1
- package/upgrades/index.d.ts +0 -1
- package/upgrades/index.js +0 -9
- package/upgrades/index.js.map +0 -1
- package/utils/access.d.ts +0 -8
- package/utils/access.js +0 -76
- package/utils/access.js.map +0 -1
- package/utils/filterModelFields.d.ts +0 -16
- package/utils/filterModelFields.js +0 -71
- package/utils/filterModelFields.js.map +0 -1
- package/utils/ownership.d.ts +0 -8
- package/utils/ownership.js +0 -33
- package/utils/ownership.js.map +0 -1
- package/utils/permissions.d.ts +0 -7
- package/utils/permissions.js +0 -91
- package/utils/permissions.js.map +0 -1
- package/utils/pluralizedTypeName.d.ts +0 -1
- package/utils/pluralizedTypeName.js +0 -20
- package/utils/pluralizedTypeName.js.map +0 -1
|
@@ -7,69 +7,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.assignModelBeforeCreate = void 0;
|
|
8
8
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
9
|
var _camelCase = _interopRequireDefault(require("lodash/camelCase"));
|
|
10
|
-
var _pluralize = _interopRequireDefault(require("pluralize"));
|
|
11
10
|
var _CmsModelPlugin = require("../../plugins/CmsModelPlugin");
|
|
12
11
|
var _validateModel = require("./validateModel");
|
|
13
12
|
var _validateLayout = require("./validateLayout");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*/
|
|
19
|
-
const disallowedModelIdEndingList = ["Response", "List", "Meta", "Input", "Sorter", "RefType"];
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Checks for the uniqueness of provided modelId, against the provided list of models.
|
|
23
|
-
* It also takes plural / singular forms of the provided modelId into account.
|
|
24
|
-
*/
|
|
25
|
-
const checkModelIdUniqueness = (modelIdList, modelId) => {
|
|
26
|
-
if (modelIdList.includes(modelId) === true) {
|
|
27
|
-
throw new _error.default(`Content model with modelId "${modelId}" already exists.`, "MODEL_ID_EXISTS", {
|
|
28
|
-
modelId
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Additionally, check if the plural form of the received modelId exists too. This prevents users
|
|
33
|
-
* from creating, for example, "event" and "events" models, which would break the GraphQL schema.
|
|
34
|
-
* 1. First check if user wants to create the "event" model, but the "events" model already exists.
|
|
35
|
-
*/
|
|
36
|
-
const pluralizedModelIdCamelCase = (0, _pluralize.default)(modelId);
|
|
37
|
-
if (modelIdList.includes(pluralizedModelIdCamelCase) === true) {
|
|
38
|
-
throw new _error.default(`Content model with modelId "${modelId}" does not exist, but a model with modelId "${pluralizedModelIdCamelCase}" does.`, "MODEL_ID_PLURAL_ERROR", {
|
|
39
|
-
modelId,
|
|
40
|
-
plural: pluralizedModelIdCamelCase
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* 2. Then check if user wants to create the "events" model, but the "event" model already exists.
|
|
46
|
-
*/
|
|
47
|
-
const singularizedModelIdCamelCase = _pluralize.default.singular(modelId);
|
|
48
|
-
if (modelIdList.includes(singularizedModelIdCamelCase) === true) {
|
|
49
|
-
throw new _error.default(`Content model with modelId "${modelId}" does not exist, but a model with modelId "${singularizedModelIdCamelCase}" does.`, "MODEL_ID_SINGULAR_ERROR", {
|
|
50
|
-
modelId,
|
|
51
|
-
singular: singularizedModelIdCamelCase
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
const checkModelIdAllowed = modelId => {
|
|
56
|
-
if (disallowedModelIdList.includes(modelId) === false) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
throw new _error.default(`Provided model ID "${modelId}" is not allowed.`);
|
|
60
|
-
};
|
|
61
|
-
const checkModelIdEndingAllowed = modelId => {
|
|
62
|
-
for (const ending of disallowedModelIdEndingList) {
|
|
63
|
-
const re = new RegExp(`${ending}$`, "i");
|
|
64
|
-
const matched = modelId.match(re);
|
|
65
|
-
if (matched === null) {
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
throw new _error.default(`ModelId that ends with "${ending}" is not allowed.`, "MODEL_ID_NOT_ALLOWED", {
|
|
69
|
-
modelId
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
};
|
|
13
|
+
var _modelId = require("./validate/modelId");
|
|
14
|
+
var _singularApiName = require("./validate/singularApiName");
|
|
15
|
+
var _pluralApiName = require("./validate/pluralApiName");
|
|
16
|
+
var _endingAllowed = require("./validate/endingAllowed");
|
|
73
17
|
const getModelId = model => {
|
|
74
18
|
const {
|
|
75
19
|
modelId,
|
|
@@ -90,33 +34,48 @@ const createOnModelBeforeCb = ({
|
|
|
90
34
|
}) => {
|
|
91
35
|
return async params => {
|
|
92
36
|
const {
|
|
93
|
-
model
|
|
37
|
+
model: newModel
|
|
94
38
|
} = params;
|
|
95
|
-
const modelId = getModelId(
|
|
39
|
+
const modelId = getModelId(newModel);
|
|
40
|
+
newModel.modelId = modelId;
|
|
96
41
|
const modelPlugin = plugins.byType(_CmsModelPlugin.CmsModelPlugin.type).find(item => item.contentModel.modelId === modelId);
|
|
97
42
|
if (modelPlugin) {
|
|
98
|
-
throw new _error.default(`Cannot create "${
|
|
99
|
-
modelId:
|
|
43
|
+
throw new _error.default(`Cannot create "${newModel.modelId}" content model because one is already registered via a plugin.`, "CONTENT_MODEL_CREATE_ERROR", {
|
|
44
|
+
modelId: newModel.modelId
|
|
100
45
|
});
|
|
101
46
|
}
|
|
102
47
|
const models = await storageOperations.models.list({
|
|
103
48
|
where: {
|
|
104
|
-
tenant:
|
|
105
|
-
locale:
|
|
49
|
+
tenant: newModel.tenant,
|
|
50
|
+
locale: newModel.locale
|
|
106
51
|
}
|
|
107
52
|
});
|
|
108
|
-
|
|
109
|
-
|
|
53
|
+
(0, _modelId.validateModelIdAllowed)({
|
|
54
|
+
model: newModel
|
|
55
|
+
});
|
|
56
|
+
(0, _endingAllowed.validateEndingAllowed)({
|
|
57
|
+
model: newModel
|
|
58
|
+
});
|
|
110
59
|
/**
|
|
111
|
-
* We need to check for:
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
60
|
+
* We need to check for the existence of:
|
|
61
|
+
* - modelId
|
|
62
|
+
* - singularApiName
|
|
63
|
+
* - pluralApiName
|
|
115
64
|
*/
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
65
|
+
for (const model of models) {
|
|
66
|
+
(0, _modelId.validateExistingModelId)({
|
|
67
|
+
existingModel: model,
|
|
68
|
+
model: newModel
|
|
69
|
+
});
|
|
70
|
+
(0, _singularApiName.validateSingularApiName)({
|
|
71
|
+
existingModel: model,
|
|
72
|
+
model: newModel
|
|
73
|
+
});
|
|
74
|
+
(0, _pluralApiName.validatePluralApiName)({
|
|
75
|
+
existingModel: model,
|
|
76
|
+
model: newModel
|
|
77
|
+
});
|
|
78
|
+
}
|
|
120
79
|
};
|
|
121
80
|
};
|
|
122
81
|
/**
|
|
@@ -128,7 +87,7 @@ const assignModelBeforeCreate = params => {
|
|
|
128
87
|
onModelBeforeCreate,
|
|
129
88
|
onModelBeforeCreateFrom,
|
|
130
89
|
storageOperations,
|
|
131
|
-
|
|
90
|
+
context
|
|
132
91
|
} = params;
|
|
133
92
|
onModelBeforeCreate.subscribe(async ({
|
|
134
93
|
model,
|
|
@@ -143,24 +102,27 @@ const assignModelBeforeCreate = params => {
|
|
|
143
102
|
*/
|
|
144
103
|
const cb = createOnModelBeforeCb({
|
|
145
104
|
storageOperations,
|
|
146
|
-
plugins
|
|
105
|
+
plugins: context.plugins
|
|
147
106
|
});
|
|
148
107
|
await cb({
|
|
149
108
|
model,
|
|
150
109
|
input
|
|
151
110
|
});
|
|
152
|
-
|
|
111
|
+
const models = await context.security.withoutAuthorization(async () => {
|
|
112
|
+
return context.cms.listModels();
|
|
113
|
+
});
|
|
153
114
|
/**
|
|
154
115
|
* and then we move onto model and fields...
|
|
155
116
|
*/
|
|
156
117
|
await (0, _validateModel.validateModel)({
|
|
118
|
+
models,
|
|
157
119
|
model,
|
|
158
|
-
|
|
120
|
+
context
|
|
159
121
|
});
|
|
160
122
|
});
|
|
161
123
|
onModelBeforeCreateFrom.subscribe(createOnModelBeforeCb({
|
|
162
124
|
storageOperations,
|
|
163
|
-
plugins
|
|
125
|
+
plugins: context.plugins
|
|
164
126
|
}));
|
|
165
127
|
};
|
|
166
128
|
exports.assignModelBeforeCreate = assignModelBeforeCreate;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["disallowedModelIdList","disallowedModelIdEndingList","checkModelIdUniqueness","modelIdList","modelId","includes","WebinyError","pluralizedModelIdCamelCase","pluralize","plural","singularizedModelIdCamelCase","singular","checkModelIdAllowed","checkModelIdEndingAllowed","ending","re","RegExp","matched","match","getModelId","model","name","camelCase","trim","createOnModelBeforeCb","plugins","storageOperations","params","modelPlugin","byType","CmsModelPlugin","type","find","item","contentModel","models","list","where","tenant","locale","map","m","assignModelBeforeCreate","onModelBeforeCreate","onModelBeforeCreateFrom","subscribe","input","validateLayout","layout","fields","cb","validateModel"],"sources":["beforeCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport camelCase from \"lodash/camelCase\";\nimport pluralize from \"pluralize\";\nimport {\n OnModelBeforeCreateFromTopicParams,\n OnModelBeforeCreateTopicParams,\n CmsModel,\n HeadlessCmsStorageOperations\n} from \"~/types\";\nimport { Topic } from \"@webiny/pubsub/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsModelPlugin } from \"~/plugins/CmsModelPlugin\";\nimport { validateModel } from \"./validateModel\";\nimport { validateLayout } from \"./validateLayout\";\n\nconst disallowedModelIdList: string[] = [\n \"contentModel\",\n \"contentModels\",\n \"contentModelGroup\",\n \"contentModelGroups\"\n];\n/**\n * This list is to disallow creating models that might interfere with GraphQL schema creation.\n * Add more if required.\n */\nconst disallowedModelIdEndingList: string[] = [\n \"Response\",\n \"List\",\n \"Meta\",\n \"Input\",\n \"Sorter\",\n \"RefType\"\n];\n\n/**\n * Checks for the uniqueness of provided modelId, against the provided list of models.\n * It also takes plural / singular forms of the provided modelId into account.\n */\nconst checkModelIdUniqueness = (modelIdList: string[], modelId: string) => {\n if (modelIdList.includes(modelId) === true) {\n throw new WebinyError(\n `Content model with modelId \"${modelId}\" already exists.`,\n \"MODEL_ID_EXISTS\",\n {\n modelId\n }\n );\n }\n /**\n * Additionally, check if the plural form of the received modelId exists too. This prevents users\n * from creating, for example, \"event\" and \"events\" models, which would break the GraphQL schema.\n * 1. First check if user wants to create the \"event\" model, but the \"events\" model already exists.\n */\n const pluralizedModelIdCamelCase = pluralize(modelId);\n if (modelIdList.includes(pluralizedModelIdCamelCase) === true) {\n throw new WebinyError(\n `Content model with modelId \"${modelId}\" does not exist, but a model with modelId \"${pluralizedModelIdCamelCase}\" does.`,\n \"MODEL_ID_PLURAL_ERROR\",\n {\n modelId,\n plural: pluralizedModelIdCamelCase\n }\n );\n }\n\n /**\n * 2. Then check if user wants to create the \"events\" model, but the \"event\" model already exists.\n */\n const singularizedModelIdCamelCase = pluralize.singular(modelId);\n if (modelIdList.includes(singularizedModelIdCamelCase) === true) {\n throw new WebinyError(\n `Content model with modelId \"${modelId}\" does not exist, but a model with modelId \"${singularizedModelIdCamelCase}\" does.`,\n \"MODEL_ID_SINGULAR_ERROR\",\n {\n modelId,\n singular: singularizedModelIdCamelCase\n }\n );\n }\n};\n\nconst checkModelIdAllowed = (modelId: string): void => {\n if (disallowedModelIdList.includes(modelId) === false) {\n return;\n }\n throw new WebinyError(`Provided model ID \"${modelId}\" is not allowed.`);\n};\n\nconst checkModelIdEndingAllowed = (modelId: string): void => {\n for (const ending of disallowedModelIdEndingList) {\n const re = new RegExp(`${ending}$`, \"i\");\n const matched = modelId.match(re);\n if (matched === null) {\n continue;\n }\n throw new WebinyError(\n `ModelId that ends with \"${ending}\" is not allowed.`,\n \"MODEL_ID_NOT_ALLOWED\",\n {\n modelId\n }\n );\n }\n};\n\nconst getModelId = (model: CmsModel): string => {\n const { modelId, name } = model;\n if (!!modelId) {\n return camelCase(modelId.trim());\n } else if (name) {\n return camelCase(name.trim());\n }\n throw new WebinyError(\n `There is no \"modelId\" or \"name\" passed into the create model method.`,\n \"MISSING_MODEL_DATA\",\n {\n model\n }\n );\n};\n\ninterface CreateOnModelBeforeCreateCbParams {\n plugins: PluginsContainer;\n storageOperations: HeadlessCmsStorageOperations;\n}\nconst createOnModelBeforeCb = ({\n plugins,\n storageOperations\n}: CreateOnModelBeforeCreateCbParams) => {\n return async (params: OnModelBeforeCreateTopicParams | OnModelBeforeCreateFromTopicParams) => {\n const { model } = params;\n\n const modelId = getModelId(model);\n\n const modelPlugin = plugins\n .byType<CmsModelPlugin>(CmsModelPlugin.type)\n .find((item: CmsModelPlugin) => item.contentModel.modelId === modelId);\n\n if (modelPlugin) {\n throw new WebinyError(\n `Cannot create \"${model.modelId}\" content model because one is already registered via a plugin.`,\n \"CONTENT_MODEL_CREATE_ERROR\",\n {\n modelId: model.modelId\n }\n );\n }\n\n const models = await storageOperations.models.list({\n where: {\n tenant: model.tenant,\n locale: model.locale\n }\n });\n const modelIdList = models.map(m => m.modelId);\n\n /**\n * We need to check for:\n * - is that exact modelId allowed\n * - is modelId unique\n * - is model ending allowed\n */\n checkModelIdAllowed(modelId);\n checkModelIdEndingAllowed(modelId);\n checkModelIdUniqueness(modelIdList, modelId);\n model.modelId = modelId;\n };\n};\n\ninterface AssignBeforeModelCreateParams {\n onModelBeforeCreate: Topic<OnModelBeforeCreateTopicParams>;\n onModelBeforeCreateFrom: Topic<OnModelBeforeCreateFromTopicParams>;\n storageOperations: HeadlessCmsStorageOperations;\n plugins: PluginsContainer;\n}\n\n/**\n * We attach both on before create and createFrom events here.\n * Callables are identical.\n */\nexport const assignModelBeforeCreate = (params: AssignBeforeModelCreateParams) => {\n const { onModelBeforeCreate, onModelBeforeCreateFrom, storageOperations, plugins } = params;\n\n onModelBeforeCreate.subscribe(async ({ model, input }) => {\n /**\n * First the layout...\n */\n validateLayout(model.layout, model.fields);\n /**\n * then we run the shared create/createFrom methods.\n */\n const cb = createOnModelBeforeCb({\n storageOperations,\n plugins\n });\n await cb({\n model,\n input\n });\n\n /**\n * and then we move onto model and fields...\n */\n await validateModel({\n model,\n plugins\n });\n });\n\n onModelBeforeCreateFrom.subscribe(\n createOnModelBeforeCb({\n storageO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AACR;AACA;IACQ,MAAM,IAAAK,4BAAa,EAAC;MAChB/B,KAAK;MACLK;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;EAEFmB,uBAAuB,CAACC,SAAS,CAC7BrB,qBAAqB,CAAC;IAClBE,iBAAiB;IACjBD;EACJ,CAAC,CAAC,CACL;AACL,CAAC;AAAC"}
|
|
1
|
+
{"version":3,"names":["getModelId","model","modelId","name","camelCase","trim","WebinyError","createOnModelBeforeCb","plugins","storageOperations","params","newModel","modelPlugin","byType","CmsModelPlugin","type","find","item","contentModel","models","list","where","tenant","locale","validateModelIdAllowed","validateEndingAllowed","validateExistingModelId","existingModel","validateSingularApiName","validatePluralApiName","assignModelBeforeCreate","onModelBeforeCreate","onModelBeforeCreateFrom","context","subscribe","input","validateLayout","layout","fields","cb","security","withoutAuthorization","cms","listModels","validateModel"],"sources":["beforeCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport camelCase from \"lodash/camelCase\";\nimport {\n OnModelBeforeCreateFromTopicParams,\n OnModelBeforeCreateTopicParams,\n CmsModel,\n HeadlessCmsStorageOperations,\n CmsContext\n} from \"~/types\";\nimport { Topic } from \"@webiny/pubsub/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsModelPlugin } from \"~/plugins/CmsModelPlugin\";\nimport { validateModel } from \"./validateModel\";\nimport { validateLayout } from \"./validateLayout\";\nimport { validateExistingModelId, validateModelIdAllowed } from \"./validate/modelId\";\nimport { validateSingularApiName } from \"./validate/singularApiName\";\nimport { validatePluralApiName } from \"./validate/pluralApiName\";\nimport { validateEndingAllowed } from \"~/crud/contentModel/validate/endingAllowed\";\n\nconst getModelId = (model: CmsModel): string => {\n const { modelId, name } = model;\n if (!!modelId) {\n return camelCase(modelId.trim());\n } else if (name) {\n return camelCase(name.trim());\n }\n throw new WebinyError(\n `There is no \"modelId\" or \"name\" passed into the create model method.`,\n \"MISSING_MODEL_DATA\",\n {\n model\n }\n );\n};\n\ninterface CreateOnModelBeforeCreateCbParams {\n plugins: PluginsContainer;\n storageOperations: HeadlessCmsStorageOperations;\n}\n\nconst createOnModelBeforeCb = ({\n plugins,\n storageOperations\n}: CreateOnModelBeforeCreateCbParams) => {\n return async (params: OnModelBeforeCreateTopicParams | OnModelBeforeCreateFromTopicParams) => {\n const { model: newModel } = params;\n\n const modelId = getModelId(newModel);\n\n newModel.modelId = modelId;\n\n const modelPlugin = plugins\n .byType<CmsModelPlugin>(CmsModelPlugin.type)\n .find((item: CmsModelPlugin) => item.contentModel.modelId === modelId);\n\n if (modelPlugin) {\n throw new WebinyError(\n `Cannot create \"${newModel.modelId}\" content model because one is already registered via a plugin.`,\n \"CONTENT_MODEL_CREATE_ERROR\",\n {\n modelId: newModel.modelId\n }\n );\n }\n\n const models = await storageOperations.models.list({\n where: {\n tenant: newModel.tenant,\n locale: newModel.locale\n }\n });\n\n validateModelIdAllowed({\n model: newModel\n });\n validateEndingAllowed({\n model: newModel\n });\n /**\n * We need to check for the existence of:\n * - modelId\n * - singularApiName\n * - pluralApiName\n */\n for (const model of models) {\n validateExistingModelId({\n existingModel: model,\n model: newModel\n });\n validateSingularApiName({\n existingModel: model,\n model: newModel\n });\n validatePluralApiName({\n existingModel: model,\n model: newModel\n });\n }\n };\n};\n\ninterface AssignBeforeModelCreateParams {\n onModelBeforeCreate: Topic<OnModelBeforeCreateTopicParams>;\n onModelBeforeCreateFrom: Topic<OnModelBeforeCreateFromTopicParams>;\n storageOperations: HeadlessCmsStorageOperations;\n context: CmsContext;\n}\n\n/**\n * We attach both on before create and createFrom events here.\n * Callables are identical.\n */\nexport const assignModelBeforeCreate = (params: AssignBeforeModelCreateParams) => {\n const { onModelBeforeCreate, onModelBeforeCreateFrom, storageOperations, context } = params;\n\n onModelBeforeCreate.subscribe(async ({ model, input }) => {\n /**\n * First the layout...\n */\n validateLayout(model.layout, model.fields);\n /**\n * then we run the shared create/createFrom methods.\n */\n const cb = createOnModelBeforeCb({\n storageOperations,\n plugins: context.plugins\n });\n await cb({\n model,\n input\n });\n const models = await context.security.withoutAuthorization(async () => {\n return context.cms.listModels();\n });\n /**\n * and then we move onto model and fields...\n */\n await validateModel({\n models,\n model,\n context\n });\n });\n\n onModelBeforeCreateFrom.subscribe(\n createOnModelBeforeCb({\n storageOperations,\n plugins: context.plugins\n })\n );\n};\n"],"mappings":";;;;;;;AAAA;AACA;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,MAAMA,UAAU,GAAIC,KAAe,IAAa;EAC5C,MAAM;IAAEC,OAAO;IAAEC;EAAK,CAAC,GAAGF,KAAK;EAC/B,IAAI,CAAC,CAACC,OAAO,EAAE;IACX,OAAO,IAAAE,kBAAS,EAACF,OAAO,CAACG,IAAI,EAAE,CAAC;EACpC,CAAC,MAAM,IAAIF,IAAI,EAAE;IACb,OAAO,IAAAC,kBAAS,EAACD,IAAI,CAACE,IAAI,EAAE,CAAC;EACjC;EACA,MAAM,IAAIC,cAAW,CAChB,sEAAqE,EACtE,oBAAoB,EACpB;IACIL;EACJ,CAAC,CACJ;AACL,CAAC;AAOD,MAAMM,qBAAqB,GAAG,CAAC;EAC3BC,OAAO;EACPC;AAC+B,CAAC,KAAK;EACrC,OAAO,MAAOC,MAA2E,IAAK;IAC1F,MAAM;MAAET,KAAK,EAAEU;IAAS,CAAC,GAAGD,MAAM;IAElC,MAAMR,OAAO,GAAGF,UAAU,CAACW,QAAQ,CAAC;IAEpCA,QAAQ,CAACT,OAAO,GAAGA,OAAO;IAE1B,MAAMU,WAAW,GAAGJ,OAAO,CACtBK,MAAM,CAAiBC,8BAAc,CAACC,IAAI,CAAC,CAC3CC,IAAI,CAAEC,IAAoB,IAAKA,IAAI,CAACC,YAAY,CAAChB,OAAO,KAAKA,OAAO,CAAC;IAE1E,IAAIU,WAAW,EAAE;MACb,MAAM,IAAIN,cAAW,CAChB,kBAAiBK,QAAQ,CAACT,OAAQ,iEAAgE,EACnG,4BAA4B,EAC5B;QACIA,OAAO,EAAES,QAAQ,CAACT;MAC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LkC;IACJ,CAAC,CAAC;IACF,MAAMhB,MAAM,GAAG,MAAMc,OAAO,CAACO,QAAQ,CAACC,oBAAoB,CAAC,YAAY;MACnE,OAAOR,OAAO,CAACS,GAAG,CAACC,UAAU,EAAE;IACnC,CAAC,CAAC;IACF;AACR;AACA;IACQ,MAAM,IAAAC,4BAAa,EAAC;MAChBzB,MAAM;MACNlB,KAAK;MACLgC;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;EAEFD,uBAAuB,CAACE,SAAS,CAC7B3B,qBAAqB,CAAC;IAClBE,iBAAiB;IACjBD,OAAO,EAAEyB,OAAO,CAACzB;EACrB,CAAC,CAAC,CACL;AACL,CAAC;AAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Topic } from "@webiny/pubsub/types";
|
|
2
|
-
import {
|
|
2
|
+
import { HeadlessCmsStorageOperations, OnModelBeforeDeleteTopicParams } from "../../types";
|
|
3
3
|
import { PluginsContainer } from "@webiny/plugins";
|
|
4
4
|
interface AssignBeforeModelDeleteParams {
|
|
5
5
|
onModelBeforeDelete: Topic<OnModelBeforeDeleteTopicParams>;
|
|
@@ -7,7 +7,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.assignModelBeforeDelete = void 0;
|
|
8
8
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
9
|
var _CmsModelPlugin = require("../../plugins/CmsModelPlugin");
|
|
10
|
-
var _valueKeyStorageConverter = require("../../utils/converters/valueKeyStorageConverter");
|
|
11
10
|
const assignModelBeforeDelete = params => {
|
|
12
11
|
const {
|
|
13
12
|
onModelBeforeDelete,
|
|
@@ -26,10 +25,7 @@ const assignModelBeforeDelete = params => {
|
|
|
26
25
|
}
|
|
27
26
|
let entries = [];
|
|
28
27
|
try {
|
|
29
|
-
const result = await storageOperations.entries.list(
|
|
30
|
-
model,
|
|
31
|
-
plugins
|
|
32
|
-
}), {
|
|
28
|
+
const result = await storageOperations.entries.list(model, {
|
|
33
29
|
where: {
|
|
34
30
|
latest: true
|
|
35
31
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["assignModelBeforeDelete","params","onModelBeforeDelete","storageOperations","plugins","subscribe","model","modelPlugin","byType","CmsModelPlugin","type","find","item","contentModel","modelId","WebinyError","entries","result","list","
|
|
1
|
+
{"version":3,"names":["assignModelBeforeDelete","params","onModelBeforeDelete","storageOperations","plugins","subscribe","model","modelPlugin","byType","CmsModelPlugin","type","find","item","contentModel","modelId","WebinyError","entries","result","list","where","latest","limit","items","ex","error","length"],"sources":["beforeDelete.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { HeadlessCmsStorageOperations, OnModelBeforeDeleteTopicParams } from \"~/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport WebinyError from \"@webiny/error\";\nimport { CmsModelPlugin } from \"~/plugins/CmsModelPlugin\";\n\ninterface AssignBeforeModelDeleteParams {\n onModelBeforeDelete: Topic<OnModelBeforeDeleteTopicParams>;\n storageOperations: HeadlessCmsStorageOperations;\n plugins: PluginsContainer;\n}\nexport const assignModelBeforeDelete = (params: AssignBeforeModelDeleteParams) => {\n const { onModelBeforeDelete, storageOperations, plugins } = params;\n\n onModelBeforeDelete.subscribe(async params => {\n const { model } = params;\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 deleted.\",\n \"CONTENT_MODEL_DELETE_ERROR\",\n {\n modelId: model.modelId\n }\n );\n }\n\n let entries = [];\n try {\n const result = await storageOperations.entries.list(model, {\n where: {\n latest: true\n },\n limit: 1\n });\n entries = result.items;\n } catch (ex) {\n throw new WebinyError(\n \"Could not retrieve a list of content entries from the model.\",\n \"ENTRIES_ERROR\",\n {\n error: ex,\n model\n }\n );\n }\n if (entries.length > 0) {\n throw new WebinyError(\n `Cannot delete content model \"${model.modelId}\" because there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8 @@
|
|
|
1
1
|
import { Topic } from "@webiny/pubsub/types";
|
|
2
|
-
import { OnModelBeforeUpdateTopicParams,
|
|
3
|
-
import { PluginsContainer } from "@webiny/plugins";
|
|
2
|
+
import { OnModelBeforeUpdateTopicParams, CmsContext } from "../../types";
|
|
4
3
|
interface AssignBeforeModelUpdateParams {
|
|
5
4
|
onModelBeforeUpdate: Topic<OnModelBeforeUpdateTopicParams>;
|
|
6
|
-
|
|
7
|
-
plugins: PluginsContainer;
|
|
5
|
+
context: CmsContext;
|
|
8
6
|
}
|
|
9
7
|
export declare const assignModelBeforeUpdate: (params: AssignBeforeModelUpdateParams) => void;
|
|
10
8
|
export {};
|
|
@@ -6,26 +6,54 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.assignModelBeforeUpdate = void 0;
|
|
7
7
|
var _validateModel = require("./validateModel");
|
|
8
8
|
var _validateLayout = require("./validateLayout");
|
|
9
|
+
var _singularApiName = require("./validate/singularApiName");
|
|
10
|
+
var _pluralApiName = require("./validate/pluralApiName");
|
|
11
|
+
var _endingAllowed = require("./validate/endingAllowed");
|
|
9
12
|
const assignModelBeforeUpdate = params => {
|
|
10
13
|
const {
|
|
11
14
|
onModelBeforeUpdate,
|
|
12
|
-
|
|
15
|
+
context
|
|
13
16
|
} = params;
|
|
14
17
|
onModelBeforeUpdate.subscribe(async ({
|
|
15
|
-
model,
|
|
18
|
+
model: newModel,
|
|
16
19
|
original
|
|
17
20
|
}) => {
|
|
18
21
|
/**
|
|
19
22
|
* First we go through the layout...
|
|
20
23
|
*/
|
|
21
|
-
(0, _validateLayout.validateLayout)(
|
|
24
|
+
(0, _validateLayout.validateLayout)(newModel.layout, newModel.fields);
|
|
25
|
+
const models = await context.security.withoutAuthorization(async () => {
|
|
26
|
+
return (await context.cms.listModels()).filter(model => {
|
|
27
|
+
return model.modelId !== newModel.modelId;
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
(0, _endingAllowed.validateEndingAllowed)({
|
|
31
|
+
model: newModel
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* We need to check for the existence of:
|
|
35
|
+
* - modelId
|
|
36
|
+
* - singularApiName
|
|
37
|
+
* - pluralApiName
|
|
38
|
+
*/
|
|
39
|
+
for (const model of models) {
|
|
40
|
+
(0, _singularApiName.validateSingularApiName)({
|
|
41
|
+
existingModel: model,
|
|
42
|
+
model: newModel
|
|
43
|
+
});
|
|
44
|
+
(0, _pluralApiName.validatePluralApiName)({
|
|
45
|
+
existingModel: model,
|
|
46
|
+
model: newModel
|
|
47
|
+
});
|
|
48
|
+
}
|
|
22
49
|
/**
|
|
23
50
|
* then the model and fields...
|
|
24
51
|
*/
|
|
25
52
|
await (0, _validateModel.validateModel)({
|
|
26
|
-
|
|
53
|
+
models,
|
|
54
|
+
model: newModel,
|
|
27
55
|
original,
|
|
28
|
-
|
|
56
|
+
context
|
|
29
57
|
});
|
|
30
58
|
});
|
|
31
59
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["assignModelBeforeUpdate","params","onModelBeforeUpdate","
|
|
1
|
+
{"version":3,"names":["assignModelBeforeUpdate","params","onModelBeforeUpdate","context","subscribe","model","newModel","original","validateLayout","layout","fields","models","security","withoutAuthorization","cms","listModels","filter","modelId","validateEndingAllowed","validateSingularApiName","existingModel","validatePluralApiName","validateModel"],"sources":["beforeUpdate.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { OnModelBeforeUpdateTopicParams, CmsContext } from \"~/types\";\nimport { validateModel } from \"./validateModel\";\nimport { validateLayout } from \"./validateLayout\";\nimport { validateSingularApiName } from \"./validate/singularApiName\";\nimport { validatePluralApiName } from \"./validate/pluralApiName\";\nimport { validateEndingAllowed } from \"~/crud/contentModel/validate/endingAllowed\";\n\ninterface AssignBeforeModelUpdateParams {\n onModelBeforeUpdate: Topic<OnModelBeforeUpdateTopicParams>;\n context: CmsContext;\n}\n\nexport const assignModelBeforeUpdate = (params: AssignBeforeModelUpdateParams) => {\n const { onModelBeforeUpdate, context } = params;\n\n onModelBeforeUpdate.subscribe(async ({ model: newModel, original }) => {\n /**\n * First we go through the layout...\n */\n validateLayout(newModel.layout, newModel.fields);\n\n const models = await context.security.withoutAuthorization(async () => {\n return (await context.cms.listModels()).filter(model => {\n return model.modelId !== newModel.modelId;\n });\n });\n\n validateEndingAllowed({\n model: newModel\n });\n /**\n * We need to check for the existence of:\n * - modelId\n * - singularApiName\n * - pluralApiName\n */\n for (const model of models) {\n validateSingularApiName({\n existingModel: model,\n model: newModel\n });\n validatePluralApiName({\n existingModel: model,\n model: newModel\n });\n }\n /**\n * then the model and fields...\n */\n await validateModel({\n models,\n model: newModel,\n original,\n context\n });\n });\n};\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACA;AAOO,MAAMA,uBAAuB,GAAIC,MAAqC,IAAK;EAC9E,MAAM;IAAEC,mBAAmB;IAAEC;EAAQ,CAAC,GAAGF,MAAM;EAE/CC,mBAAmB,CAACE,SAAS,CAAC,OAAO;IAAEC,KAAK,EAAEC,QAAQ;IAAEC;EAAS,CAAC,KAAK;IACnE;AACR;AACA;IACQ,IAAAC,8BAAc,EAACF,QAAQ,CAACG,MAAM,EAAEH,QAAQ,CAACI,MAAM,CAAC;IAEhD,MAAMC,MAAM,GAAG,MAAMR,OAAO,CAACS,QAAQ,CAACC,oBAAoB,CAAC,YAAY;MACnE,OAAO,CAAC,MAAMV,OAAO,CAACW,GAAG,CAACC,UAAU,EAAE,EAAEC,MAAM,CAACX,KAAK,IAAI;QACpD,OAAOA,KAAK,CAACY,OAAO,KAAKX,QAAQ,CAACW,OAAO;MAC7C,CAAC,CAAC;IACN,CAAC,CAAC;IAEF,IAAAC,oCAAqB,EAAC;MAClBb,KAAK,EAAEC;IACX,CAAC,CAAC;IACF;AACR;AACA;AACA;AACA;AACA;IACQ,KAAK,MAAMD,KAAK,IAAIM,MAAM,EAAE;MACxB,IAAAQ,wCAAuB,EAAC;QACpBC,aAAa,EAAEf,KAAK;QACpBA,KAAK,EAAEC;MACX,CAAC,CAAC;MACF,IAAAe,oCAAqB,EAAC;QAClBD,aAAa,EAAEf,KAAK;QACpBA,KAAK,EAAEC;MACX,CAAC,CAAC;IACN;IACA;AACR;AACA;IACQ,MAAM,IAAAgB,4BAAa,EAAC;MAChBX,MAAM;MACNN,KAAK,EAAEC,QAAQ;MACfC,QAAQ;MACRJ;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.ensureSingularApiName = exports.ensurePluralApiName = void 0;
|
|
8
|
+
var _camelCase = _interopRequireDefault(require("lodash/camelCase"));
|
|
9
|
+
var _upperFirst = _interopRequireDefault(require("lodash/upperFirst"));
|
|
10
|
+
var _pluralize = _interopRequireDefault(require("pluralize"));
|
|
11
|
+
const ensureSingularApiName = model => {
|
|
12
|
+
if (!model.singularApiName) {
|
|
13
|
+
return (0, _upperFirst.default)((0, _camelCase.default)(model.modelId));
|
|
14
|
+
}
|
|
15
|
+
return model.singularApiName;
|
|
16
|
+
};
|
|
17
|
+
exports.ensureSingularApiName = ensureSingularApiName;
|
|
18
|
+
const ensurePluralApiName = model => {
|
|
19
|
+
if (!model.pluralApiName) {
|
|
20
|
+
return (0, _pluralize.default)(ensureSingularApiName(model));
|
|
21
|
+
}
|
|
22
|
+
return model.pluralApiName;
|
|
23
|
+
};
|
|
24
|
+
exports.ensurePluralApiName = ensurePluralApiName;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ensureSingularApiName","model","singularApiName","upperFirst","camelCase","modelId","ensurePluralApiName","pluralApiName","pluralize"],"sources":["modelApiName.ts"],"sourcesContent":["import camelCase from \"lodash/camelCase\";\nimport upperFirst from \"lodash/upperFirst\";\nimport pluralize from \"pluralize\";\nimport { CmsModel } from \"~/types\";\n\nexport const ensureSingularApiName = (model: CmsModel): string => {\n if (!model.singularApiName) {\n return upperFirst(camelCase(model.modelId));\n }\n return model.singularApiName;\n};\n\nexport const ensurePluralApiName = (model: CmsModel): string => {\n if (!model.pluralApiName) {\n return pluralize(ensureSingularApiName(model));\n }\n return model.pluralApiName;\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAGO,MAAMA,qBAAqB,GAAIC,KAAe,IAAa;EAC9D,IAAI,CAACA,KAAK,CAACC,eAAe,EAAE;IACxB,OAAO,IAAAC,mBAAU,EAAC,IAAAC,kBAAS,EAACH,KAAK,CAACI,OAAO,CAAC,CAAC;EAC/C;EACA,OAAOJ,KAAK,CAACC,eAAe;AAChC,CAAC;AAAC;AAEK,MAAMI,mBAAmB,GAAIL,KAAe,IAAa;EAC5D,IAAI,CAACA,KAAK,CAACM,aAAa,EAAE;IACtB,OAAO,IAAAC,kBAAS,EAACR,qBAAqB,CAACC,KAAK,CAAC,CAAC;EAClD;EACA,OAAOA,KAAK,CAACM,aAAa;AAC9B,CAAC;AAAC"}
|
|
@@ -4,11 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createFieldStorageId = void 0;
|
|
7
|
+
var _getBaseFieldType = require("../../utils/getBaseFieldType");
|
|
7
8
|
const createFieldStorageId = params => {
|
|
8
9
|
const {
|
|
9
10
|
type,
|
|
10
11
|
id
|
|
11
12
|
} = params;
|
|
12
|
-
return `${
|
|
13
|
+
return `${(0, _getBaseFieldType.getBaseFieldType)({
|
|
14
|
+
type
|
|
15
|
+
})}@${id}`;
|
|
13
16
|
};
|
|
14
17
|
exports.createFieldStorageId = createFieldStorageId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createFieldStorageId","params","type","id"],"sources":["createFieldStorageId.ts"],"sourcesContent":["import { CmsModelField } from \"~/types\";\n\nexport const createFieldStorageId = (params: Pick<CmsModelField, \"id\" | \"type\">): string => {\n const { type, id } = params;\n return `${type}@${id}`;\n};\n"],"mappings":";;;;;;AAEO,MAAMA,oBAAoB,GAAIC,MAA0C,IAAa;EACxF,MAAM;IAAEC,IAAI;IAAEC;EAAG,CAAC,GAAGF,MAAM;EAC3B,OAAQ,
|
|
1
|
+
{"version":3,"names":["createFieldStorageId","params","type","id","getBaseFieldType"],"sources":["createFieldStorageId.ts"],"sourcesContent":["import { CmsModelField } from \"~/types\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\n\nexport const createFieldStorageId = (params: Pick<CmsModelField, \"id\" | \"type\">): string => {\n const { type, id } = params;\n return `${getBaseFieldType({ type })}@${id}`;\n};\n"],"mappings":";;;;;;AACA;AAEO,MAAMA,oBAAoB,GAAIC,MAA0C,IAAa;EACxF,MAAM;IAAEC,IAAI;IAAEC;EAAG,CAAC,GAAGF,MAAM;EAC3B,OAAQ,GAAE,IAAAG,kCAAgB,EAAC;IAAEF;EAAK,CAAC,CAAE,IAAGC,EAAG,EAAC;AAChD,CAAC;AAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.assignModelDefaultFields = void 0;
|
|
7
|
+
var _utils = require("@webiny/utils");
|
|
8
|
+
const createDefaultFields = () => {
|
|
9
|
+
return [{
|
|
10
|
+
id: (0, _utils.generateAlphaNumericLowerCaseId)(8),
|
|
11
|
+
fieldId: "title",
|
|
12
|
+
type: "text",
|
|
13
|
+
label: "Title",
|
|
14
|
+
validation: [{
|
|
15
|
+
name: "required",
|
|
16
|
+
message: "Title is a required field."
|
|
17
|
+
}],
|
|
18
|
+
listValidation: [],
|
|
19
|
+
renderer: {
|
|
20
|
+
name: "text-input"
|
|
21
|
+
}
|
|
22
|
+
}, {
|
|
23
|
+
id: (0, _utils.generateAlphaNumericLowerCaseId)(8),
|
|
24
|
+
fieldId: "description",
|
|
25
|
+
type: "long-text",
|
|
26
|
+
label: "Description",
|
|
27
|
+
validation: [],
|
|
28
|
+
listValidation: [],
|
|
29
|
+
renderer: {
|
|
30
|
+
name: "long-text-text-area"
|
|
31
|
+
}
|
|
32
|
+
}, {
|
|
33
|
+
id: (0, _utils.generateAlphaNumericLowerCaseId)(8),
|
|
34
|
+
fieldId: "image",
|
|
35
|
+
type: "file",
|
|
36
|
+
label: "Image",
|
|
37
|
+
validation: [],
|
|
38
|
+
listValidation: [],
|
|
39
|
+
renderer: {
|
|
40
|
+
name: "file-input"
|
|
41
|
+
},
|
|
42
|
+
settings: {
|
|
43
|
+
imagesOnly: true
|
|
44
|
+
}
|
|
45
|
+
}];
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* We only assign default fields if there are no fields in the model already.
|
|
50
|
+
*/
|
|
51
|
+
const assignModelDefaultFields = model => {
|
|
52
|
+
if (model.fields && model.fields.length !== 0) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
model.fields = createDefaultFields();
|
|
56
|
+
model.layout = [[model.fields[0].id], [model.fields[1].id, model.fields[2].id]];
|
|
57
|
+
};
|
|
58
|
+
exports.assignModelDefaultFields = assignModelDefaultFields;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createDefaultFields","id","generateAlphaNumericLowerCaseId","fieldId","type","label","validation","name","message","listValidation","renderer","settings","imagesOnly","assignModelDefaultFields","model","fields","length","layout"],"sources":["defaultFields.ts"],"sourcesContent":["import { CmsModelCreateInput, CmsModelFieldInput } from \"~/types\";\nimport { generateAlphaNumericLowerCaseId } from \"@webiny/utils\";\n\nconst createDefaultFields = (): CmsModelFieldInput[] => {\n return [\n {\n id: generateAlphaNumericLowerCaseId(8),\n fieldId: \"title\",\n type: \"text\",\n label: \"Title\",\n validation: [\n {\n name: \"required\",\n message: \"Title is a required field.\"\n }\n ],\n listValidation: [],\n renderer: {\n name: \"text-input\"\n }\n },\n {\n id: generateAlphaNumericLowerCaseId(8),\n fieldId: \"description\",\n type: \"long-text\",\n label: \"Description\",\n validation: [],\n listValidation: [],\n renderer: {\n name: \"long-text-text-area\"\n }\n },\n {\n id: generateAlphaNumericLowerCaseId(8),\n fieldId: \"image\",\n type: \"file\",\n label: \"Image\",\n validation: [],\n listValidation: [],\n renderer: {\n name: \"file-input\"\n },\n settings: {\n imagesOnly: true\n }\n }\n ];\n};\n\n/**\n * We only assign default fields if there are no fields in the model already.\n */\nexport const assignModelDefaultFields = (model: CmsModelCreateInput): void => {\n if (model.fields && model.fields.length !== 0) {\n return;\n }\n\n model.fields = createDefaultFields();\n model.layout = [[model.fields[0].id], [model.fields[1].id, model.fields[2].id]];\n};\n"],"mappings":";;;;;;AACA;AAEA,MAAMA,mBAAmB,GAAG,MAA4B;EACpD,OAAO,CACH;IACIC,EAAE,EAAE,IAAAC,sCAA+B,EAAC,CAAC,CAAC;IACtCC,OAAO,EAAE,OAAO;IAChBC,IAAI,EAAE,MAAM;IACZC,KAAK,EAAE,OAAO;IACdC,UAAU,EAAE,CACR;MACIC,IAAI,EAAE,UAAU;MAChBC,OAAO,EAAE;IACb,CAAC,CACJ;IACDC,cAAc,EAAE,EAAE;IAClBC,QAAQ,EAAE;MACNH,IAAI,EAAE;IACV;EACJ,CAAC,EACD;IACIN,EAAE,EAAE,IAAAC,sCAA+B,EAAC,CAAC,CAAC;IACtCC,OAAO,EAAE,aAAa;IACtBC,IAAI,EAAE,WAAW;IACjBC,KAAK,EAAE,aAAa;IACpBC,UAAU,EAAE,EAAE;IACdG,cAAc,EAAE,EAAE;IAClBC,QAAQ,EAAE;MACNH,IAAI,EAAE;IACV;EACJ,CAAC,EACD;IACIN,EAAE,EAAE,IAAAC,sCAA+B,EAAC,CAAC,CAAC;IACtCC,OAAO,EAAE,OAAO;IAChBC,IAAI,EAAE,MAAM;IACZC,KAAK,EAAE,OAAO;IACdC,UAAU,EAAE,EAAE;IACdG,cAAc,EAAE,EAAE;IAClBC,QAAQ,EAAE;MACNH,IAAI,EAAE;IACV,CAAC;IACDI,QAAQ,EAAE;MACNC,UAAU,EAAE;IAChB;EACJ,CAAC,CACJ;AACL,CAAC;;AAED;AACA;AACA;AACO,MAAMC,wBAAwB,GAAIC,KAA0B,IAAW;EAC1E,IAAIA,KAAK,CAACC,MAAM,IAAID,KAAK,CAACC,MAAM,CAACC,MAAM,KAAK,CAAC,EAAE;IAC3C;EACJ;EAEAF,KAAK,CAACC,MAAM,GAAGf,mBAAmB,EAAE;EACpCc,KAAK,CAACG,MAAM,GAAG,CAAC,CAACH,KAAK,CAACC,MAAM,CAAC,CAAC,CAAC,CAACd,EAAE,CAAC,EAAE,CAACa,KAAK,CAACC,MAAM,CAAC,CAAC,CAAC,CAACd,EAAE,EAAEa,KAAK,CAACC,MAAM,CAAC,CAAC,CAAC,CAACd,EAAE,CAAC,CAAC;AACnF,CAAC;AAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getContentModelDescriptionFieldId = void 0;
|
|
8
|
+
var _getBaseFieldType = require("../../../utils/getBaseFieldType");
|
|
9
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
10
|
+
const getContentModelDescriptionFieldId = (fields, descriptionFieldId) => {
|
|
11
|
+
/**
|
|
12
|
+
* If there are no fields defined, we will just set as null.
|
|
13
|
+
*/
|
|
14
|
+
if (fields.length === 0) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* If description field is not defined, let us find possible one.
|
|
19
|
+
*/
|
|
20
|
+
if (!descriptionFieldId) {
|
|
21
|
+
const descriptionField = fields.find(field => {
|
|
22
|
+
return (0, _getBaseFieldType.getBaseFieldType)(field) === "long-text" && !field.multipleValues;
|
|
23
|
+
});
|
|
24
|
+
return (descriptionField === null || descriptionField === void 0 ? void 0 : descriptionField.fieldId) || null;
|
|
25
|
+
}
|
|
26
|
+
const target = fields.find(field => field.fieldId === descriptionFieldId && (0, _getBaseFieldType.getBaseFieldType)(field) === "long-text");
|
|
27
|
+
if (!target) {
|
|
28
|
+
throw new _error.default(`Field selected for the description field does not exist in the model.`, "VALIDATION_ERROR", {
|
|
29
|
+
fieldId: descriptionFieldId,
|
|
30
|
+
fields
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (target.multipleValues) {
|
|
34
|
+
throw new _error.default(`Fields that accept multiple values cannot be used as the entry description.`, "ENTRY_TITLE_FIELD_TYPE", {
|
|
35
|
+
storageId: target.storageId,
|
|
36
|
+
fieldId: target.fieldId,
|
|
37
|
+
type: target.type
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return target.fieldId;
|
|
41
|
+
};
|
|
42
|
+
exports.getContentModelDescriptionFieldId = getContentModelDescriptionFieldId;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getContentModelDescriptionFieldId","fields","descriptionFieldId","length","descriptionField","find","field","getBaseFieldType","multipleValues","fieldId","target","WebinyError","storageId","type"],"sources":["descriptionField.ts"],"sourcesContent":["import { CmsModelField } from \"~/types\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\nimport WebinyError from \"@webiny/error\";\n\nexport const getContentModelDescriptionFieldId = (\n fields: CmsModelField[],\n descriptionFieldId?: 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 description field is not defined, let us find possible one.\n */\n if (!descriptionFieldId) {\n const descriptionField = fields.find(field => {\n return getBaseFieldType(field) === \"long-text\" && !field.multipleValues;\n });\n return descriptionField?.fieldId || null;\n }\n const target = fields.find(\n field => field.fieldId === descriptionFieldId && getBaseFieldType(field) === \"long-text\"\n );\n if (!target) {\n throw new WebinyError(\n `Field selected for the description field does not exist in the model.`,\n \"VALIDATION_ERROR\",\n {\n fieldId: descriptionFieldId,\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 description.`,\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,iCAAiC,GAAG,CAC7CC,MAAuB,EACvBC,kBAAkC,KACN;EAC5B;AACJ;AACA;EACI,IAAID,MAAM,CAACE,MAAM,KAAK,CAAC,EAAE;IACrB,OAAO,IAAI;EACf;EACA;AACJ;AACA;EACI,IAAI,CAACD,kBAAkB,EAAE;IACrB,MAAME,gBAAgB,GAAGH,MAAM,CAACI,IAAI,CAACC,KAAK,IAAI;MAC1C,OAAO,IAAAC,kCAAgB,EAACD,KAAK,CAAC,KAAK,WAAW,IAAI,CAACA,KAAK,CAACE,cAAc;IAC3E,CAAC,CAAC;IACF,OAAO,CAAAJ,gBAAgB,aAAhBA,gBAAgB,uBAAhBA,gBAAgB,CAAEK,OAAO,KAAI,IAAI;EAC5C;EACA,MAAMC,MAAM,GAAGT,MAAM,CAACI,IAAI,CACtBC,KAAK,IAAIA,KAAK,CAACG,OAAO,KAAKP,kBAAkB,IAAI,IAAAK,kCAAgB,EAACD,KAAK,CAAC,KAAK,WAAW,CAC3F;EACD,IAAI,CAACI,MAAM,EAAE;IACT,MAAM,IAAIC,cAAW,CAChB,uEAAsE,EACvE,kBAAkB,EAClB;MACIF,OAAO,EAAEP,kBAAkB;MAC3BD;IACJ,CAAC,CACJ;EACL;EACA,IAAIS,MAAM,CAACF,cAAc,EAAE;IACvB,MAAM,IAAIG,cAAW,CAChB,6EAA4E,EAC7E,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,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getContentModelImageFieldId = void 0;
|
|
8
|
+
var _getBaseFieldType = require("../../../utils/getBaseFieldType");
|
|
9
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
10
|
+
const getContentModelImageFieldId = (fields, imageFieldId) => {
|
|
11
|
+
/**
|
|
12
|
+
* If there are no fields defined, we will just set as null.
|
|
13
|
+
*/
|
|
14
|
+
if (fields.length === 0) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* If image field is not defined, let us find possible one.
|
|
19
|
+
*/
|
|
20
|
+
if (!imageFieldId) {
|
|
21
|
+
const imageField = fields.find(field => {
|
|
22
|
+
var _field$settings;
|
|
23
|
+
return (0, _getBaseFieldType.getBaseFieldType)(field) === "file" && !field.multipleValues && ((_field$settings = field.settings) === null || _field$settings === void 0 ? void 0 : _field$settings.imagesOnly);
|
|
24
|
+
});
|
|
25
|
+
return (imageField === null || imageField === void 0 ? void 0 : imageField.fieldId) || null;
|
|
26
|
+
}
|
|
27
|
+
const target = fields.find(field => {
|
|
28
|
+
var _field$settings2;
|
|
29
|
+
return field.fieldId === imageFieldId && (0, _getBaseFieldType.getBaseFieldType)(field) === "file" && ((_field$settings2 = field.settings) === null || _field$settings2 === void 0 ? void 0 : _field$settings2.imagesOnly);
|
|
30
|
+
});
|
|
31
|
+
if (!target) {
|
|
32
|
+
throw new _error.default(`Field selected for the image field does not exist in the model.`, "VALIDATION_ERROR", {
|
|
33
|
+
fieldId: imageFieldId,
|
|
34
|
+
fields
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (target.multipleValues) {
|
|
38
|
+
throw new _error.default(`Fields that accept multiple values cannot be used as the entry image.`, "ENTRY_TITLE_FIELD_TYPE", {
|
|
39
|
+
storageId: target.storageId,
|
|
40
|
+
fieldId: target.fieldId,
|
|
41
|
+
type: target.type
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return target.fieldId;
|
|
45
|
+
};
|
|
46
|
+
exports.getContentModelImageFieldId = getContentModelImageFieldId;
|
|
@@ -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"}
|