contentful-migration
Version:
Migration tooling for contentful
38 lines • 1.58 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");
class TypeChangeValidator {
constructor() {
this.hooks = [__1.ApiHook.SaveContentType];
}
validate({ contentType, publishedContentType }) {
const errors = [];
if (!publishedContentType) {
return errors;
}
const fieldsById = (0, lodash_1.keyBy)(contentType.fields.toRaw(), 'id');
const parentFieldsById = (0, lodash_1.keyBy)(publishedContentType.fields.toRaw(), 'id');
for (const fieldId of Object.keys(fieldsById)) {
const parentField = parentFieldsById[fieldId];
// we don't care about a type change if the previous change was a deletion
if (parentField && !parentField.deleted) {
const fieldType = fieldsById[fieldId].type;
const parentFieldType = parentField.type;
if (fieldType !== parentFieldType) {
errors.push({
type: 'InvalidAction',
message: errors_1.default.field.NO_TYPE_CHANGE(fieldId, contentType.id, parentFieldType, fieldType)
});
}
}
}
return errors;
}
}
exports.default = TypeChangeValidator;
//# sourceMappingURL=type-change.js.map