Merge pull request #15609 from strapi/enhancement/add-datatype-diff-type

This commit is contained in:
Ben Irvin 2023-01-31 09:05:01 +01:00 committed by GitHub
commit e73b7873c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 12 deletions

View File

@ -346,7 +346,7 @@ class TransferEngine<
keys.forEach((key) => {
const sourceSchema = sourceSchemas[key];
const destinationSchema = destinationSchemas[key];
const schemaDiffs = compareSchemas(destinationSchema, sourceSchema, strategy);
const schemaDiffs = compareSchemas(sourceSchema, destinationSchema, strategy);
if (schemaDiffs.length) {
diffs[key] = schemaDiffs;
@ -364,15 +364,19 @@ class TransferEngine<
const path = diff.path.join('.');
if (diff.kind === 'added') {
return `Added "${path}": "${diff.value}" (${diff.type})`;
return `${path} exists in destination schema but not in source schema`;
}
if (diff.kind === 'deleted') {
return `Removed "${path}"`;
return `${path} exists in source schema but not in destination schema`;
}
if (diff.kind === 'modified') {
return `Modified "${path}": "${diff.values[0]}" (${diff.types[0]}) => "${diff.values[1]}" (${diff.types[1]})`;
if (diff.types[0] === diff.types[1]) {
return `Schema value changed at "${path}": "${diff.values[0]}" (${diff.types[0]}) => "${diff.values[1]}" (${diff.types[1]})`;
}
return `Schema has differing data types at "${path}": "${diff.values[0]}" (${diff.types[0]}) => "${diff.values[1]}" (${diff.types[1]})`;
}
throw new TransferEngineValidationError(`Invalid diff found for "${uid}"`, {

View File

@ -38,14 +38,6 @@ export const diff = (a: unknown, b: unknown, ctx: Context = createContext()): Di
return diffs;
};
if (aType === 'undefined') {
return added();
}
if (bType === 'undefined') {
return deleted();
}
if (isArray(a) && isArray(b)) {
let k = 0;
@ -77,6 +69,14 @@ export const diff = (a: unknown, b: unknown, ctx: Context = createContext()): Di
}
if (!isEqual(a, b)) {
if (aType === 'undefined') {
return added();
}
if (bType === 'undefined') {
return deleted();
}
return modified();
}