Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(database): adding/removing object(group) fields not working #603

Merged
merged 1 commit into from
Apr 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion modules/database/src/adapters/utils/validateFieldChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,39 @@
function validateSchemaFields(oldSchemaFields: Indexable, newSchemaFields: Indexable) {
const tempObj: Fields = {};

Object.keys(oldSchemaFields).forEach(key => {
if (
!oldSchemaFields[key].type &&
!isString(oldSchemaFields[key]) &&
!isArray(oldSchemaFields[key])
) {
tempObj[key] = validateSchemaFields(oldSchemaFields[key], newSchemaFields[key]);
} else {
const oldType = oldSchemaFields[key].type ?? oldSchemaFields[key];
if (isNil(newSchemaFields)) return;
const newType = newSchemaFields[key]?.type ?? null;
if (!newType) return;
if (oldType === DataTypes.JSONB && newType === 'JSON') return;
if (isArray(oldType) && isArray(newType)) {
if (JSON.stringify(oldType[0]) !== JSON.stringify(newType[0]))
if (typeof oldType[0] === 'object') {
validateObject(oldType[0], newType[0]);
} else if (JSON.stringify(oldType[0]) !== JSON.stringify(newType[0]))
throw ConduitError.forbidden('Invalid schema types');
} else if (typeof oldType === 'object') {
validateObject(oldType, newType);
} else if (!isEqual(oldType, newType)) {
// TODO: Support schema field type migration
throw ConduitError.forbidden('Invalid schema types');
}
}
});
return newSchemaFields;
}

Check notice on line 48 in modules/database/src/adapters/utils/validateFieldChanges.ts

View check run for this annotation

codefactor.io / CodeFactor

modules/database/src/adapters/utils/validateFieldChanges.ts#L20-L48

Complex Method
function validateObject(oldType: any, newType: any) {

Check notice on line 49 in modules/database/src/adapters/utils/validateFieldChanges.ts

View check run for this annotation

codefactor.io / CodeFactor

modules/database/src/adapters/utils/validateFieldChanges.ts#L49

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)

Check notice on line 49 in modules/database/src/adapters/utils/validateFieldChanges.ts

View check run for this annotation

codefactor.io / CodeFactor

modules/database/src/adapters/utils/validateFieldChanges.ts#L49

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
if (!oldType.hasOwnProperty('type') && !newType.hasOwnProperty('type')) {
validateSchemaFields(oldType, newType);
}
if (JSON.stringify(oldType[0]) !== JSON.stringify(newType[0]))
throw ConduitError.forbidden('Invalid schema types');
}