contentful-migration
Version:
Migration tooling for contentful
32 lines • 1.39 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const __1 = require("../");
const errors_1 = __importDefault(require("./errors"));
const lodash_1 = require("lodash");
const deletedFieldError = function (contentTypeId, fieldId) {
return {
type: 'InvalidAction',
message: errors_1.default.field.NO_DELETE_WITHOUT_OMIT(fieldId, contentTypeId)
};
};
class FieldDeletionValidator {
constructor() {
this.hooks = [__1.ApiHook.SaveContentType];
}
validate({ contentType, publishedContentType }) {
const deletedFields = contentType.fields.filter((field) => field.deleted);
const omittedFieldsInParent = publishedContentType
? publishedContentType.fields.filter((field) => field.omitted)
: [];
const deletedIds = deletedFields.map((field) => field.id);
const omittedIds = omittedFieldsInParent.map((field) => field.id);
const deletedButNotOmitted = (0, lodash_1.difference)(deletedIds, omittedIds);
const errors = deletedButNotOmitted.map((fieldId) => deletedFieldError(contentType.id, fieldId));
return errors;
}
}
exports.default = FieldDeletionValidator;
//# sourceMappingURL=field-deletion.js.map